:root {
  --primary: #4A90D9;
  --primary-dark: #3570B0;
  --danger: #E74C3C;
  --success: #27AE60;
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --border: #E1E4E8;
  --radius: 6px;
}

/* Dark mode */
[data-theme="dark"] {
  --primary: #5BA0E6;
  --primary-dark: #4A90D9;
  --danger: #E85D4A;
  --success: #2ECC71;
  --bg: #1A1D23;
  --surface: #23272E;
  --text: #D4D7DD;
  --text-light: #8B92A0;
  --border: #353A44;
}
[data-theme="dark"] .login-container { box-shadow: 0 2px 12px rgba(0,0,0,0.3); }
[data-theme="dark"] .timer-section,
[data-theme="dark"] .card { box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
[data-theme="dark"] .modal-content { box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
[data-theme="dark"] .alert-error { background: #3D1F1F; color: #F5A0A0; border-color: #5C2A2A; }
[data-theme="dark"] .badge-archived { background: #2A2D33; color: var(--text-light); }
[data-theme="dark"] .nav-links a.active { background: rgba(91, 160, 230, 0.12); }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { color: var(--text); }
[data-theme="dark"] .btn-icon { color: var(--text); }
[data-theme="dark"] .hour-line { border-top-color: #2A2D33; }
[data-theme="dark"] .entry-block { opacity: 0.95; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #5BA0E6;
    --primary-dark: #4A90D9;
    --danger: #E85D4A;
    --success: #2ECC71;
    --bg: #1A1D23;
    --surface: #23272E;
    --text: #D4D7DD;
    --text-light: #8B92A0;
    --border: #353A44;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Nav */
.main-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  height: 56px;
}
.nav-brand a {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  margin-right: 2rem;
}
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: var(--text-light);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { color: var(--primary); background: rgba(74, 144, 217, 0.08); }
.theme-toggle { font-size: 1.2rem; opacity: 0.7; vertical-align: middle; }
.theme-toggle:hover { opacity: 1; }
.nav-logout { margin-left: auto; }

/* Container */
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem 1.25rem; border: none; border-radius: var(--radius);
  font-size: 0.9rem; cursor: pointer; font-weight: 500;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-start { background: var(--success); color: #fff; font-size: 1.1rem; padding: 0.6rem 2rem; }
.btn-start:hover { background: #219A52; }
.btn-stop { background: var(--danger); color: #fff; font-size: 1.1rem; padding: 0.6rem 2rem; }
.btn-stop:hover { background: #C0392B; }
.btn-nav-arrow {
  background: var(--primary); color: #fff; font-size: 1.1rem; padding: 0.4rem 0.75rem;
  text-decoration: none; line-height: 1;
}
.btn-nav-arrow:hover { background: var(--primary-dark); }
.btn-link { background: none; color: var(--primary); border: none; cursor: pointer; font-size: 0.85rem; padding: 0.25rem 0; }
.btn-link:hover { text-decoration: underline; }
.btn-block { width: 100%; }
.btn-icon {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 0.25rem; opacity: 0.5; transition: opacity 0.15s;
}
.btn-icon:hover { opacity: 1; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; color: var(--text-light); }
.form-control, input[type="text"], input[type="password"], input[type="email"],
input[type="date"], input[type="time"], input[type="datetime-local"],
input[type="number"], select, textarea {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.9rem; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(74,144,217,0.15); }

/* Alert */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #FDECEA; color: var(--danger); border: 1px solid #F5C6CB; }

/* Login */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: var(--bg);
}
.login-container {
  background: var(--surface); padding: 2.5rem; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08); width: 100%; max-width: 380px;
}
.login-container h1 { text-align: center; margin-bottom: 1.5rem; color: var(--primary); }

/* Timer Section */
.timer-section {
  background: var(--surface); border-radius: 8px; padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); margin-bottom: 1.5rem;
}
.timer-controls {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.timer-input { flex: 1; min-width: 200px; font-size: 1rem; padding: 0.6rem 0.75rem; }
.timer-select { width: 180px; padding: 0.6rem 0.5rem; }
.timer-display {
  font-family: 'Courier New', monospace; font-size: 1.5rem; font-weight: 700;
  color: var(--text); min-width: 110px; text-align: center;
}
input.timer-start-input {
  width: 110px; min-width: 110px; max-width: 110px; text-align: center; font-size: 1.1rem;
  padding: 0.4rem 0.5rem; font-family: 'Courier New', monospace; flex: none;
}
.timer-clickable {
  cursor: pointer; border-bottom: 1px dashed var(--primary);
}
.timer-clickable:hover { color: var(--primary); }
.manual-entry-toggle { margin-top: 0.75rem; }
.manual-entry { margin-top: 0.75rem; }
.manual-fields { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.manual-fields input { width: auto; }

/* Entry List */
.entries-section { }
.entry-group { margin-bottom: 1rem; }
.entry-group-header {
  display: flex; justify-content: space-between; padding: 0.5rem 0;
  border-bottom: 2px solid var(--border); font-weight: 600; font-size: 0.9rem;
}
.entry-total { font-family: 'Courier New', monospace; }
.entry-row {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0;
  border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.entry-row:hover { background: var(--bg); }
.entry-color {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.entry-desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-project { color: var(--text-light); font-size: 0.8rem; width: 120px; text-align: right; }
.entry-time { color: var(--text-light); font-size: 0.8rem; width: 130px; text-align: right; }
.entry-duration {
  font-family: 'Courier New', monospace; font-weight: 600; width: 80px; text-align: right;
}
.entry-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.entry-overlap { background: rgba(231, 76, 60, 0.08); }
.entry-overlap:hover { background: rgba(231, 76, 60, 0.14); }
[data-theme="dark"] .entry-overlap { background: rgba(231, 76, 60, 0.12); }
[data-theme="dark"] .entry-overlap:hover { background: rgba(231, 76, 60, 0.2); }
.conflict-indicator {
  text-align: center; font-size: 0.7rem; font-weight: 600; color: var(--danger);
  background: rgba(231, 76, 60, 0.1); border-left: 3px solid var(--danger);
  padding: 2px 0; letter-spacing: 0.05em; text-transform: uppercase;
}
.editable-time { cursor: pointer; border-bottom: 1px dashed transparent; padding: 0 1px; }
.editable-time:hover { border-bottom-color: var(--primary); color: var(--primary); }
.inline-time-input {
  width: 75px; padding: 1px 4px; font-size: 0.8rem; border: 1px solid var(--primary);
  border-radius: 3px; background: var(--surface); color: var(--text);
  font-family: inherit; text-align: center;
}
.editable-desc, .editable-project { cursor: pointer; border-bottom: 1px dashed transparent; }
.editable-desc:hover, .editable-project:hover { border-bottom-color: var(--primary); color: var(--primary); }
.inline-desc-input {
  width: 100%; padding: 1px 4px; font-size: 0.9rem; border: 1px solid var(--primary);
  border-radius: 3px; background: var(--surface); color: var(--text); font-family: inherit;
}
.inline-project-select {
  width: 120px; padding: 1px 2px; font-size: 0.8rem; border: 1px solid var(--primary);
  border-radius: 3px; background: var(--surface); color: var(--text); font-family: inherit;
}

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--surface); border-radius: 8px; padding: 1.5rem;
  width: 100%; max-width: 440px; box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-content h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Page Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-header h2 { margin: 0; }

/* Card */
.card {
  background: var(--surface); border-radius: 8px; padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card h3 { margin-bottom: 1rem; }

/* Form rows */
.form-row { display: flex; gap: 0.75rem; }
.color-input { height: 38px; padding: 2px; cursor: pointer; }

/* Project Tree */
.project-tree { }
.project-node { margin-bottom: 0.5rem; }
.project-row {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem;
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.child-row { margin-left: 2rem; margin-top: 2px; }
.project-color { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.project-name { flex: 1; font-weight: 500; }
.project-target { color: var(--text-light); font-size: 0.8rem; }
.project-actions { display: flex; gap: 0.25rem; }

/* Badge */
.badge { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 10px; }
.badge-archived { background: #F0F0F0; color: var(--text-light); }

/* Reports */
.report-form .form-group { margin-bottom: 0; }
.report-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); }
.report-tab {
  padding: 0.6rem 1.25rem; text-decoration: none; color: var(--text-light);
  border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 0.9rem;
}
.report-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.report-tab:hover { color: var(--text); }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.report-table th { text-align: left; padding: 0.5rem; border-bottom: 2px solid var(--border); color: var(--text-light); font-weight: 600; }
.report-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.report-table .parent-row td { font-weight: 500; }
.report-table .total-row td { border-top: 2px solid var(--text); }
.mono { font-family: 'Courier New', monospace; }
.text-success { color: var(--success); }
.text-warn { color: #E67E22; }

/* Chart row */

/* Responsive */
@media (max-width: 768px) {
  .chart-row { flex-direction: column !important; }
}
@media (max-width: 640px) {
  .timer-controls { flex-direction: column; }
  .timer-input, .timer-select { width: 100%; }
  .entry-row { flex-wrap: wrap; }
  .entry-time, .entry-project { width: auto; }
  .nav-links { font-size: 0.8rem; gap: 0; }
}
