:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #dfe3e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2226;
    --text: #e7e9ec;
    --muted: #9aa1ab;
    --border: #33373d;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --danger-hover: #fca5a5;
  }
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --surface: #1f2226;
  --text: #e7e9ec;
  --muted: #9aa1ab;
  --border: #33373d;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --danger: #f87171;
  --danger-hover: #fca5a5;
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #dfe3e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
}

/* ---- App shell: dark sidebar + main content area ---- */

:root {
  --sidebar-bg: #1b1d22;
  --sidebar-text: #b6bac2;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #2a2d34;
  --sidebar-active-bg: #2f333c;
  --sidebar-border: #2a2d34;
  --sidebar-accent: #3b82f6;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: #fff;
  padding: 0.5rem 0.6rem 1.25rem;
  font-size: 1rem;
}

.sidebar-logo {
  width: 100%;
  height: auto;
  max-width: 170px;
  display: block;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-nav .nav-section {
  margin: 1rem 0 0.35rem;
  padding: 0 0.6rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #767b85;
  text-transform: uppercase;
}

.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
}

.sidebar-nav .nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-nav .nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar-nav .nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.sidebar-nav .nav-item.admin-only {
  display: none;
}

.admin-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-right select {
  width: auto;
}

.topbar-right a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.topbar-right a:hover {
  color: var(--primary);
}

main {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.auth-page main {
  max-width: 400px;
  margin-top: 3rem;
}

.auth-theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: auto;
}

.auth-logo-wrap {
  display: flex;
  justify-content: center;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.auth-logo {
  width: 100%;
  max-width: 220px;
  height: auto;
  display: block;
}

.placeholder-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  color: var(--muted);
  font-size: 1.1rem;
  text-align: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1.15rem;
  margin-top: 0;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  margin-top: 0.75rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

textarea {
  resize: vertical;
  min-height: 3rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: var(--primary);
  color: #fff;
  margin-top: 1rem;
}

button:hover {
  background: var(--primary-hover);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: var(--danger-hover);
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.row-actions button {
  margin-top: 0;
  margin-right: 0.35rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.filters {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filters > div {
  min-width: 160px;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.75rem;
  min-height: 1.2rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.section-gap {
  margin-top: 2rem;
}

/* ---- Timesheet grid ---- */

.timesheet-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.timesheet-toolbar .spacer {
  flex: 1;
}

.timesheet-toolbar select {
  width: auto;
  min-width: 160px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  margin-top: 0;
}

.icon-btn:hover {
  background: var(--bg);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  background: var(--surface);
}

.week-nav button {
  margin: 0;
  padding: 0.2rem 0.5rem;
  background: transparent;
  color: var(--text);
  border: none;
}

.week-nav button:hover {
  background: var(--bg);
}

.week-nav button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.week-nav button:disabled:hover {
  background: transparent;
}

.week-nav .week-label {
  font-size: 0.9rem;
  min-width: 120px;
  text-align: center;
}

.timesheet-table {
  width: 100%;
  border-collapse: collapse;
}

.timesheet-table th, .timesheet-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.4rem;
  font-size: 0.85rem;
}

.timesheet-table th {
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}

.timesheet-table th.col-date {
  white-space: nowrap;
}

.timesheet-table th.col-project,
.timesheet-table td.col-project {
  text-align: left;
  width: 320px;
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
}

.project-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.project-label .customer-name {
  color: var(--muted);
}

.timesheet-table td.col-day {
  text-align: center;
  padding: 0.3rem;
}

.timesheet-table input.hour-input {
  width: 64px;
  text-align: center;
  padding: 0.35rem;
  margin: 0 auto;
}

.timesheet-table td.col-total,
.timesheet-table th.col-total {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}

.timesheet-table tr.total-row td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.timesheet-footer {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ---- Time Tracker ---- */

.time-tracker-add-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.time-tracker-add-row input,
.time-tracker-add-row select {
  width: auto;
}

.time-tracker-add-row #description {
  flex: 1;
  min-width: 200px;
}

.time-tracker-add-row #project {
  min-width: 180px;
}

.time-tracker-add-row #start-time,
.time-tracker-add-row #end-time {
  width: 110px;
}

.tt-duration-display {
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.time-tracker-add-row button {
  margin-top: 0;
}

.time-tracker-week-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.tt-week-section {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.75rem 1rem;
}

.tt-week-section:first-child {
  margin-top: 0;
}

.tt-week-header {
  display: flex;
  justify-content: space-between;
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.day-group {
  margin-top: 0.75rem;
}

.tt-week-header + .day-group {
  margin-top: 0;
}

.day-group-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0 0 0.4rem;
  border-bottom: 1px solid var(--border);
}

.day-group-entries {
  display: flex;
  flex-direction: column;
}

.day-group-entries .tt-entry:last-child {
  border-bottom: none;
}

.tt-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.tt-desc {
  flex: 1;
  min-width: 120px;
}

.tt-project {
  color: var(--muted);
  white-space: nowrap;
}

.tt-time-range {
  white-space: nowrap;
  color: var(--muted);
  min-width: 100px;
  text-align: center;
}

.tt-duration {
  font-weight: 600;
  min-width: 50px;
  text-align: right;
}

.tt-delete {
  margin: 0;
  padding: 0.2rem 0.5rem;
  background: transparent;
  color: var(--muted);
  border: none;
}

.tt-delete:hover {
  color: var(--danger);
}

/* ---- Calendar ---- */

.view-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.view-tab {
  margin: 0;
  padding: 0.4rem 0.9rem;
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 0;
  font-size: 0.85rem;
}

.view-tab.active {
  background: var(--primary);
  color: #fff;
}

.calendar-scroll {
  max-height: 640px;
  overflow-y: auto;
}

.calendar-days-row {
  display: flex;
  min-width: 100%;
}

.cal-hour-gutter {
  width: 56px;
  flex-shrink: 0;
}

.cal-day-header {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.cal-hour-row-label {
  box-sizing: border-box;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  padding-right: 6px;
  text-align: right;
}

.cal-day-col {
  flex: 1;
  min-width: 90px;
  border-left: 1px solid var(--border);
}

.cal-day-track {
  position: relative;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 39px,
    var(--border) 39px,
    var(--border) 40px
  );
}

.cal-block {
  position: absolute;
  /* left/width set inline per-block by calendar.js (overlap layout) */
  border-radius: 4px;
  padding: 2px 4px;
  color: #fff;
  overflow: hidden;
  font-size: 0.7rem;
  line-height: 1.2;
  box-sizing: border-box;
}

.cal-block-desc {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-block-project {
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-chip {
  margin: 2px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  color: #fff;
  display: inline-block;
}

/* ---- Charts ---- */

.chart-axis-label {
  font-size: 9px;
  fill: var(--muted);
}

.chart-total-label {
  font-size: 9px;
  fill: var(--text);
}

.report-charts {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.report-chart-col {
  flex: 1;
  min-width: 280px;
}

.donut-chart-wrapper {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.donut-center-label {
  font-size: 14px;
  font-weight: 700;
  fill: var(--text);
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.donut-legend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.donut-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

.donut-legend-value {
  color: var(--muted);
  margin-left: auto;
}

/* ---- Dashboard ---- */

.stat-cards {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 180px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 0.35rem;
}

.stat-value-text {
  font-size: 1.1rem;
}

.dashboard-main-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.dashboard-charts-col {
  flex: 2;
  min-width: 320px;
}

.dashboard-activities-col {
  flex: 1;
  min-width: 260px;
}

.activity-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
