:root {
  --bg: #14161a;
  --surface: #1c1f24;
  --surface-2: #23272e;
  --border: #2b3038;
  --text: #e9e7e2;
  --text-dim: #9aa1ab;
  --accent: #57e2c6;
  --pause: #f5b942;
  --danger: #f2685c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* Auth */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
}
.auth-card h1 { margin-top: 0; font-size: 22px; }
.auth-card h2 { font-size: 16px; color: var(--text-dim); font-weight: 500; }
.muted { color: var(--text-dim); font-size: 13px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
#letterhead-preview { max-width: 180px; max-height: 100px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; display: block; margin-bottom: 10px; }

label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }
textarea { resize: vertical; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #0c1210; border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); color: #200; border-color: var(--danger); }
button.link-btn { background: none; border: none; color: var(--text-dim); }
button.link-btn:hover { color: var(--accent); }
#timer-adjust-start { display: block; margin-top: 6px; font-size: 12px; padding: 0; text-align: left; width: auto; }

.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.nav-btn { background: none; border: none; color: var(--text-dim); }
.nav-btn.active { color: var(--accent); font-weight: 600; }

.nav-dropdown { position: relative; }
.dropdown-toggle::after { content: " ▾"; font-size: 10px; opacity: 0.7; }
.dropdown-menu {
  display: none;
  flex-direction: column;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  gap: 2px;
  z-index: 30;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.nav-dropdown:hover .dropdown-menu,
.dropdown-menu.show { display: flex; }
.dropdown-item {
  background: none;
  border: none;
  color: var(--text-dim);
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.dropdown-item:hover { background: var(--surface-2); color: var(--accent); }
.dropdown-item.active { color: var(--accent); font-weight: 600; }

.sub-nav { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.subnav-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); border-radius: 8px; padding: 6px 14px; }
.subnav-btn.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-dim); }

main { padding: 24px; max-width: 1000px; margin: 0 auto; }
.view h3 { margin-top: 0; }

/* Tracker */
.tracker-card, .manual-entry-card, .month-logs-card, .new-project-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.tracker-inputs { display: flex; gap: 16px; }
.tracker-inputs .field { flex: 1; }
.timer-display {
  font-size: 48px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 20px 0;
  color: var(--accent);
}
.timer-controls { display: flex; gap: 10px; justify-content: center; }

.manual-row, .new-project-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.manual-row input, .new-project-row input { width: auto; flex: 1; min-width: 120px; }

/* Filters */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; }

/* Table */
.entries-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; }
.entries-table th, .entries-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: top;
}
.entries-table th { color: var(--text-dim); font-weight: 500; }
.entries-table td button { padding: 5px 10px; font-size: 12px; margin-right: 6px; }
.entries-table td:last-child { white-space: nowrap; }
.action-buttons { display: flex; align-items: center; gap: 6px; }
.action-buttons button { margin-right: 0; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0 !important;
  font-size: 14px;
  line-height: 1;
}

.entries-table th.sortable { cursor: pointer; user-select: none; }
.entries-table th.sortable:hover { color: var(--text); }
.entries-table th.sortable .sort-arrow { margin-left: 4px; opacity: 0.7; }

.entries-table tr.over-budget td { color: var(--danger); }
.entries-table tr.over-budget td:nth-child(2) { font-weight: 600; }

.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); width: auto; }
.checkbox-label input { width: auto; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 340px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------------------------------------------------------------------
   Responsive (mobile browsers)
   --------------------------------------------------------------------- */
@media (max-width: 700px) {
  .auth-card { width: auto; max-width: 90vw; }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .topbar nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
  }
  .nav-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 13px;
  }
  .topbar-right { font-size: 12px; gap: 8px; }

  main { padding: 12px; }

  .tracker-card, .manual-entry-card, .month-logs-card, .new-project-row {
    padding: 14px;
  }
  .tracker-inputs { flex-direction: column; gap: 12px; }
  .timer-display { font-size: 36px; margin: 14px 0; }
  .timer-controls { flex-wrap: wrap; }

  .manual-row, .new-project-row, .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .manual-row input, .manual-row select,
  .new-project-row input, .new-project-row select,
  .filters input, .filters select {
    width: 100%;
    min-width: 0;
  }

  .sub-nav { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .subnav-btn { white-space: nowrap; flex-shrink: 0; }

  /* Wide tables scroll horizontally instead of squeezing columns unreadably. */
  .entries-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .modal-card { width: auto; max-width: 90vw; }
}
