/* ========= RESET & BASE ========= */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f4f6fb;
  color: #1f2937;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

:root {
  /* App theme: red accent on near-black sidebar */
  --brand: #E31E24;
  --brand-dark: #B01419;
  --brand-light: #fde2e3;
  --accent: #10b981;
  --danger: #B01419;
  --warn: #F5B91C;
  --bg: #f6f3f1;
  --card: #ffffff;
  --border: #e5e2df;
  --muted: #6b7280;
  --text: #1a1a1a;
  --sidebar-bg: #0e0e0e;
  --sidebar-text: #d8d3cf;
  --sidebar-hover: #1f1f1f;
  --sidebar-active: #E31E24;
}

/* ========= LOGIN ========= */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0e0e0e 0%, #3a0608 45%, #E31E24 100%);
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #E31E24, #8a0f14);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; margin: 0 auto 16px; color: #fff;
  box-shadow: 0 10px 20px -5px rgba(227,30,36,0.45);
}
.login-header h1 { margin: 0 0 6px; font-size: 24px; color: #111827; }
.login-header p { margin: 0; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; color: #374151; }
.login-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}
.login-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,30,36,0.18); }
.login-error { color: var(--danger); min-height: 20px; font-size: 13px; }
.login-hint {
  margin-top: 20px; padding: 12px; background: #f3f4f6;
  border-radius: 8px; font-size: 12px; color: var(--muted); text-align: center;
}

/* ========= BUTTONS ========= */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  border: none; border-radius: 8px; padding: 8px 16px;
  font-weight: 500; font-size: 14px; transition: all 0.15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }
.btn-block { width: 100%; padding: 12px; }

.btn-play, .btn-stop {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.btn-play { background: var(--accent); }
.btn-play:hover { background: #059669; }
.btn-stop { background: var(--danger); }
.btn-stop:hover { background: #dc2626; }

/* ========= SHELL ========= */
.app-shell { display: flex; min-height: 100vh; }

/* ========= SIDEBAR ========= */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid #1f2937; }
.brand-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #E31E24, #8a0f14);
  border-radius: 8px; display: flex; color: #fff;
  align-items: center; justify-content: center; font-size: 18px;
}
.brand-title { font-weight: 600; color: #fff; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-size: 14px; transition: all 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { padding: 14px; border-top: 1px solid #1f2937; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; background: #1f2937; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #E31E24, #8a0f14);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
}
.user-meta { flex: 1; overflow: hidden; }
.user-name { color: #fff; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--muted); font-size: 11px; text-transform: capitalize; }
.sidebar-footer .btn-ghost { color: var(--sidebar-text); }
.sidebar-footer .btn-ghost:hover { background: var(--sidebar-hover); color: #fff; }

/* ========= MAIN ========= */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { margin: 0; font-size: 20px; font-weight: 600; color: #111827; }

.mini-timer {
  display: flex; align-items: center; gap: 8px;
  background: #f9fafb; padding: 6px; border-radius: 10px;
  border: 1px solid var(--border);
}
.mini-input, .mini-select {
  padding: 6px 10px; border: 1px solid transparent; background: #fff;
  border-radius: 6px; outline: none; font-size: 13px;
}
.mini-input { width: 220px; }
.mini-select { max-width: 160px; }
.mini-display {
  font-family: "SF Mono", Monaco, "Courier New", monospace;
  font-size: 16px; font-weight: 600;
  padding: 0 12px; color: #111827;
  font-variant-numeric: tabular-nums;
}
.mini-timer.running { background: #ecfdf5; border-color: #6ee7b7; }
.mini-timer.running .mini-display { color: #059669; }

/* ========= VIEWS ========= */
.view { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* ========= PANELS ========= */
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.panel-header h3 { margin: 0; font-size: 15px; font-weight: 600; color: #111827; }
.muted { color: var(--muted); font-size: 13px; }

/* ========= STATS GRID ========= */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
}
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.stat-value { font-size: 28px; font-weight: 700; color: #111827; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col .panel { margin: 0; }

/* ========= WEEK BARS ========= */
.week-bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding: 10px 0; }
.week-bar {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.week-bar-fill {
  width: 100%; background: linear-gradient(180deg, #E31E24, #8a0f14);
  border-radius: 6px 6px 0 0; min-height: 4px;
  transition: height 0.3s ease;
  position: relative;
}
.week-bar-fill:hover { opacity: 0.85; }
.week-bar-label { font-size: 11px; color: var(--muted); }
.week-bar-hours { font-size: 11px; font-weight: 600; color: #374151; }

/* ========= TOP PROJECTS ========= */
.top-projects { display: flex; flex-direction: column; gap: 10px; }
.top-project-row {
  display: flex; align-items: center; gap: 12px;
}
.top-project-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.top-project-name { flex: 1; font-size: 13px; color: #374151; }
.top-project-bar { flex: 2; height: 8px; background: #f3f4f6; border-radius: 4px; overflow: hidden; }
.top-project-bar-fill { height: 100%; border-radius: 4px; }
.top-project-hours { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }

/* ========= ENTRY LIST ========= */
.entry-list { display: flex; flex-direction: column; gap: 8px; }
.entry-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff;
  transition: background 0.15s;
}
.entry-row:hover { background: #f9fafb; }
.entry-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.entry-main { flex: 1; min-width: 0; }
.entry-desc { font-weight: 500; color: #111827; font-size: 13px; }
.entry-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.entry-time { font-family: "SF Mono", Monaco, monospace; font-size: 13px; color: #374151; font-variant-numeric: tabular-nums; }
.entry-duration { font-weight: 600; color: #111827; font-variant-numeric: tabular-nums; min-width: 70px; text-align: right; }
.entry-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 28px; height: 28px; border: none; background: transparent;
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: #f3f4f6; color: #111827; }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }

/* ========= BIG TIMER ========= */
.big-timer-panel { padding: 24px; }
.big-timer-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.big-input {
  flex: 1; min-width: 200px; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: 8px; outline: none; font-size: 15px;
}
.big-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,30,36,0.18); }
.big-select {
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; outline: none; min-width: 160px;
}
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; cursor: pointer; }
.big-display {
  font-family: "SF Mono", Monaco, monospace;
  font-size: 28px; font-weight: 700;
  padding: 0 16px; color: #111827;
  font-variant-numeric: tabular-nums; min-width: 160px; text-align: center;
}
#bigStart, #bigStop { padding: 12px 28px; font-size: 15px; }

/* ========= CALENDAR TIMESHEET ========= */
.week-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.week-nav span { font-weight: 500; color: #4b5563; }

.calendar-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 12px; min-height: 480px;
}
.cal-day {
  background: #fafbfd; border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; min-height: 480px;
  cursor: pointer; transition: all 0.15s;
  overflow: hidden;
}
.cal-day:hover { border-color: var(--brand); background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.04); }
.cal-today { border-color: var(--brand); background: #fff; }
.cal-today .cal-day-num { color: var(--brand); }
.cal-day-header {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: #fff;
}
.cal-day-name { font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 0.05em; }
.cal-day-num { font-size: 20px; font-weight: 700; color: #111827; line-height: 1; margin-top: 2px; }
.cal-day-total {
  background: #f3f4f6; color: var(--muted);
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cal-day-total.has-hours { background: var(--brand); color: #fff; }
.cal-day-body {
  flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
.cal-entry {
  background: #fff; border: 1px solid var(--border); border-left: 3px solid #94a3b8;
  border-radius: 6px; padding: 8px 10px; cursor: pointer;
  transition: all 0.15s;
}
.cal-entry:hover { transform: translateX(2px); box-shadow: 0 2px 6px rgba(0,0,0,0.06); }
.cal-entry-top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.cal-entry-dur { font-weight: 700; color: #111827; }
.cal-entry-project { font-size: 12px; font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.cal-entry-tag {
  display: inline-block; background: #f3f4f6; color: #4b5563;
  font-size: 10px; padding: 1px 6px; border-radius: 4px; margin-top: 4px;
}
.cal-entry-desc { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.cal-empty {
  color: #c7c9cd; font-size: 12px; text-align: center;
  padding: 14px 8px; border: 1px dashed var(--border); border-radius: 6px;
  transition: all 0.15s;
}
.cal-day:hover .cal-empty { color: var(--brand); border-color: var(--brand); background: rgba(227,30,36,0.04); }

/* ========= ENTRY MODAL (TrackingTime style) ========= */
.entry-modal { width: 100%; }
.entry-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: -8px 0 16px;
}
.entry-modal-date { font-weight: 600; color: #111827; font-size: 15px; }
.entry-modal-date #eDateLabel { margin-left: 6px; }
.section-label {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-top: 12px; margin-bottom: 6px;
}
.time-row { display: flex; gap: 10px; align-items: center; }
.time-pill, .duration-pill {
  display: flex; align-items: center; gap: 8px;
  background: #f6f3f1; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px;
}
.time-pill { flex: 1; }
.duration-pill { min-width: 90px; justify-content: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.time-icon { color: var(--muted); }
.time-pill input[type="time"] {
  border: none; background: transparent; outline: none;
  font-family: "SF Mono", Monaco, monospace; font-size: 14px; font-weight: 600;
  width: 80px; padding: 0;
}
.time-dash { color: var(--muted); }
.big-select-full {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; outline: none; font-size: 14px;
}
.big-select-full:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,30,36,0.18); }
.details-area {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; outline: none; font-size: 14px; resize: vertical;
}
.details-area:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,30,36,0.18); }
.entry-modal-bottom {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border);
}
.entry-modal-bottom .btn-primary { padding: 10px 24px; }
.danger-link { color: var(--danger); border-color: #fecaca !important; }
.danger-link:hover { background: #fee2e2 !important; }

/* ========= PROJECT GROUPS ========= */
.project-group { margin-bottom: 24px; }
.project-group-title {
  font-size: 13px; font-weight: 700; color: #111827;
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 0 0 12px; padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

/* Make optgroups readable in dropdowns */
optgroup { font-weight: 700; color: #111827; background: #f3f4f6; }
option { font-weight: normal; color: #111827; background: #fff; padding: 4px; }

/* ========= PROJECTS GRID ========= */
.projects-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.project-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; position: relative; transition: all 0.15s; cursor: pointer;
}
.project-card:hover { border-color: var(--brand); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.project-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.project-card-color { width: 12px; height: 12px; border-radius: 3px; }
.project-card-name { font-weight: 600; color: #111827; flex: 1; font-size: 15px; }
.project-card-client { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.project-card-stats { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.project-card-bar { height: 6px; background: #f3f4f6; border-radius: 3px; margin-top: 10px; overflow: hidden; }
.project-card-bar-fill { height: 100%; border-radius: 3px; }

/* ========= CLIENTS GRID ========= */
.clients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.client-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: all 0.15s;
}
.client-card:hover { border-color: var(--brand); }
.client-dot { width: 14px; height: 14px; border-radius: 4px; }
.client-name { flex: 1; font-weight: 500; color: #111827; }

/* ========= TABLES ========= */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 12px; background: #f9fafb;
  font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.data-table tr:hover td { background: #f9fafb; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge.open { background: #dbeafe; color: #1e40af; }
.badge.in_progress { background: #fef3c7; color: #92400e; }
.badge.done { background: #d1fae5; color: #065f46; }
.badge.admin { background: #fce7f3; color: #9f1239; }
.badge.member { background: #e0e7ff; color: #3730a3; }

/* ========= INLINE SELECT ========= */
.inline-select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; outline: none; font-size: 13px;
}
.report-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ========= MODAL ========= */
[hidden] { display: none !important; }
.modal-host {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-host[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(17, 24, 39, 0.5); backdrop-filter: blur(2px);
}
.modal-card {
  position: relative; background: #fff; border-radius: 12px;
  padding: 24px; width: 100%; max-width: 520px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  max-height: 90vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 16px; font-size: 18px; }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; color: #374151; font-size: 13px; }
.modal-form input, .modal-form select, .modal-form textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.modal-form input:focus, .modal-form select:focus, .modal-form textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(227,30,36,0.18);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-row { display: flex; gap: 10px; }
.form-row > label { flex: 1; }

/* ========= TOAST ========= */
.toast-host { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; padding: 10px 16px;
  border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  font-size: 13px; animation: slideIn 0.2s ease;
}
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========= HELPERS ========= */
.color-swatch {
  display: inline-block; width: 24px; height: 24px; border-radius: 6px;
  margin-right: 6px; cursor: pointer; border: 2px solid transparent;
}
.color-swatch.selected { border-color: #111827; }

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .mini-input { width: 140px; }
}
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .brand-title, .brand-sub, .nav-item span:not(.nav-icon), .user-meta, .sidebar-footer .btn-ghost { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .mini-timer { flex-wrap: wrap; }
}
