/* LawScroll Diary — Components. Built on tokens.css; load that first. */

/* ============ Layout shell ============ */
.app-content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  padding-top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px) + var(--space-5));
}
@media (max-width: 767px) {
  .app-content { padding-bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom, 0px) + var(--space-5)); }
}

/* ============ Top bar ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  height: var(--topbar-height);
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-outline-variant);
}
.topbar-logo { display: flex; align-items: center; flex-shrink: 0; }
.topbar-logo img { height: 20px; width: auto; display: block; }
/* Dark mode: invert the black logo to light instead of needing a second file */
:root[data-theme="dark"] .topbar-logo img { filter: invert(1) brightness(1.3); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .topbar-logo img { filter: invert(1) brightness(1.3); }
}

.topbar-nav-desktop { display: none; gap: var(--space-4); align-items: center; }
.topbar-nav-desktop a {
  color: var(--color-on-surface-variant);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
}
.topbar-nav-desktop a:hover { color: var(--color-on-surface); text-decoration: none; }
.topbar-nav-desktop a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--color-on-surface-variant);
  font-size: 1.15rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-surface-container); }
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--color-error);
}

.more-toggle-desktop {
  background: none; border: none; cursor: pointer;
  color: var(--color-on-surface-variant); font-size: var(--font-size-sm); font-weight: 500;
  padding: var(--space-2) 0;
}
.more-toggle-desktop:hover { color: var(--color-on-surface); }

@media (min-width: 768px) {
  .topbar-nav-desktop { display: flex; }
}

/* ============ "More" panel — a dropdown on desktop, a bottom sheet on mobile ============ */
.more-panel {
  position: fixed;
  z-index: 50;
  background: var(--color-surface-container);
  border: 1px solid var(--color-outline-variant);
  box-shadow: var(--elevation-2);
  padding: var(--space-3);
  display: none;
}
.more-panel.open { display: block; }
.more-panel a, .more-panel button.link-style {
  display: block;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-on-surface);
  font-size: var(--font-size-base);
  width: 100%; text-align: left; background: none; border: none; cursor: pointer; font-family: inherit;
}
.more-panel a:hover, .more-panel button.link-style:hover { background: var(--color-surface-container-high); text-decoration: none; }
.more-panel hr { border: none; border-top: 1px solid var(--color-outline-variant); margin: var(--space-2) 0; }

@media (max-width: 767px) {
  .more-panel {
    left: 0; right: 0; bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    max-height: 70vh; overflow-y: auto;
  }
}
@media (min-width: 768px) {
  .more-panel {
    top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px) + 4px);
    right: var(--space-4);
    min-width: 220px;
    border-radius: var(--radius-md);
  }
}

.more-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.32); z-index: 45; display: none;
}
.more-backdrop.open { display: block; }

/* ============ Bottom tab bar (mobile only) — the primary "fast in court" navigation ============ */
.bottomnav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  height: calc(var(--bottomnav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-surface);
  border-top: 1px solid var(--color-outline-variant);
  box-shadow: var(--elevation-2);
}
.bottomnav a, .bottomnav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--color-on-surface-variant);
  font-size: 0.6875rem;
  font-weight: 500;
  background: none; border: none; font-family: inherit; cursor: pointer;
}
.bottomnav .nav-icon { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--color-primary); }

@media (min-width: 768px) {
  .bottomnav { display: none; }
}

/* ============ Cards — flat, hairline border; a colored LEFT edge carries state, not a filled box ============ */
.card {
  background: var(--color-surface-container);
  border: 1px solid var(--color-outline-variant);
  border-left: 3px solid var(--color-outline-variant);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card.state-urgent { border-left-color: var(--color-error); }
.card.state-success { border-left-color: var(--color-success); }
.card.state-primary { border-left-color: var(--color-primary); }

/* ============ Badges ============ */
.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  background: var(--color-surface-container-high);
  color: var(--color-on-surface-variant);
  white-space: nowrap;
}
.badge.urgent, .badge.critical { background: var(--color-error-container); color: var(--color-on-error-container); }
.badge.ok, .badge.success { background: var(--color-success-container); color: var(--color-on-success-container); }
.badge.high, .badge.warning { background: var(--color-warning-container); color: var(--color-on-warning-container); }

/* ============ Buttons ============ */
button, .btn {
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-outline);
  background: var(--color-surface);
  color: var(--color-on-surface);
  cursor: pointer;
  line-height: 1.3;
}
button:hover { background: var(--color-surface-container); }
button[type="submit"], .btn-filled {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: transparent;
}
button[type="submit"]:hover, .btn-filled:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ Forms ============ */
input[type="text"], input[type="email"], input[type="date"], input[type="time"],
input[type="password"], input[type="number"], select, textarea {
  font-family: inherit;
  font-size: var(--font-size-base);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-outline);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-on-surface);
}
input:focus, select:focus, textarea:focus { border-color: var(--color-primary); }
label { font-size: var(--font-size-sm); color: var(--color-on-surface-variant); }

/* ============ Tables ============ */
table { border-collapse: collapse; width: 100%; margin-bottom: var(--space-4); }
th, td { text-align: left; padding: var(--space-3); border-bottom: 1px solid var(--color-outline-variant); font-size: var(--font-size-sm); }
th { color: var(--color-on-surface-variant); font-weight: 500; }
@media (max-width: 600px) {
  table, thead, tbody, tr { display: block; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--color-outline-variant); padding: var(--space-2) 0; }
  td { border: none; padding: 4px 0; }
}

/* ============ Misc ============ */
.inline { display: inline; }
.metric { display: inline-block; min-width: 130px; margin: var(--space-2) var(--space-5) var(--space-2) 0; }
.metric .num { font-size: var(--font-size-xl); font-weight: 600; display: block; color: var(--color-primary); }
hr { border: none; border-top: 1px solid var(--color-outline-variant); margin: var(--space-4) 0; }
