/* Reset, app shell, navigation, widget grid. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  /*
   * min-height, never height. With `height: 100%` the body box is pinned to the
   * viewport, the main grid overflows it, and the footer ends up painted on top
   * of the last week of the calendar.
   */
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --- banner --------------------------------------------------------------- */

/*
 * [hidden] must be restated here. The browser's default is
 * `[hidden] { display: none }`, which a class selector with `display: flex`
 * outranks - so setting `.hidden = true` did nothing and the dismiss button
 * appeared to be dead. Any class that sets `display` has to opt back in.
 */
.banner[hidden] {
  display: none;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid var(--danger);
  font-size: var(--text-sm);
}

.banner--warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom-color: var(--warn);
}

.banner code {
  font-family: var(--font-mono);
  font-size: 0.95em;
}

.banner__text {
  flex: 1;
  min-width: 0;
}

.banner__close {
  flex: none;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  padding: 0 var(--space-2);
  cursor: pointer;
  opacity: 0.7;
}

.banner__close:hover {
  opacity: 1;
}

/* --- header --------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header__identity {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.app-title {
  font-size: var(--text-lg);
}

.app-clock {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  font-size: var(--text-base);
  transition: background 120ms ease, border-color 120ms ease;
}

.icon-button {
  padding: 0;
  font-size: var(--text-lg);
}

.icon-button--small,
.text-button--small {
  min-width: 1.85rem;
  min-height: 1.85rem;
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
}

.icon-button:hover,
.text-button:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.icon-button:disabled,
.text-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-button[aria-busy="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.sync-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 200ms ease;
}

.sync-dot[data-state="ok"] { background: var(--ok); }
.sync-dot[data-state="loading"] { background: var(--warn); }
.sync-dot[data-state="error"] { background: var(--danger); }

/* --- shell + nav ---------------------------------------------------------- */

.shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

/*
 * Landscape and desktop: a vertical rail down the left.
 * Portrait phones and tablets: a bottom bar. Same markup either way.
 */
.nav {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: 6rem;
  padding: var(--space-3) var(--space-2);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) var(--space-1);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--text-xs);
}

.nav__item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav__item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.nav__icon {
  font-size: var(--text-lg);
  line-height: 1;
}

.app-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: var(--gap);
}

.page[hidden] {
  display: none;
}

/* --- widget grid ---------------------------------------------------------- */

.widget-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  grid-auto-rows: var(--row-unit);
  gap: var(--gap);
  align-items: stretch;
}

.empty-page {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
  color: var(--text-dim);
}

/* --- finance tabs --------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--gap);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--text-base);
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 650;
}

/* --- footer --------------------------------------------------------------- */

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-faint);
  font-size: var(--text-xs);
}

.app-footer__endpoint {
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- responsive ----------------------------------------------------------- */

/*
 * Portrait on a small screen: nav moves to the bottom, where a thumb is.
 * Landscape keeps the rail, which is what a phone held sideways and every
 * tablet on a stand actually wants.
 */
@media (orientation: portrait) and (max-width: 900px) {
  .shell {
    flex-direction: column;
  }

  .app-main {
    order: 1;
    padding: var(--space-3);
  }

  .nav {
    order: 2;
    position: sticky;
    bottom: 0;
    z-index: 5;
    flex-direction: row;
    width: 100%;
    padding: var(--space-2);
    padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
  }

  .nav__item {
    flex: 1;
  }
}

@media (max-width: 720px) {
  .app-header {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }

  .app-title {
    font-size: var(--text-base);
  }
}

/* Landscape on a phone: shrink the rail so the content keeps the screen. */
@media (orientation: landscape) and (max-height: 540px) {
  .nav {
    width: 4rem;
  }

  .nav__label {
    display: none;
  }
}

/*
 * Wall display: exactly one screenful, no scrollbar, no footer chrome.
 * A kiosk nobody touches must never have content below the fold.
 */
:root[data-view="wall"] .app-footer {
  display: none;
}

:root[data-view="wall"] body {
  height: 100dvh;
  overflow: hidden;
}

:root[data-view="wall"] .app-main {
  overflow: hidden;
}

:root[data-view="wall"] .widget-grid {
  grid-auto-rows: minmax(0, var(--row-unit));
}

@media print {
  .app-header__actions,
  .nav,
  .app-footer {
    display: none;
  }
}
