/* =========
   THEME TOKENS
   ========= */

:root {
  --bg: #050816;
  --bg-elevated: #050816;
  --bg-elevated-soft: #0b1020;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-strong: #4f46e5;
  --accent-text: #e0e7ff;
  --danger: #f97373;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --shadow-soft: 0 18px 50px rgba(15, 23, 42, 0.65);
  --radius-lg: 18px;
  --radius-pill: 999px;
  --ring-shadow: 0 0 0 1px rgba(148, 163, 184, 0.25);
  --transition-fast: 160ms ease-out;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  --bg: #f4f4fb;
  --bg-elevated: #ffffff;
  --bg-elevated-soft: #f9fafb;
  --border-subtle: rgba(15, 23, 42, 0.06);
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --accent-strong: #4338ca;
  --accent-text: #312e81;
  --danger: #dc2626;
  --text: #020617;
  --text-muted: #6b7280;
  --shadow-soft: 0 16px 40px rgba(15, 23, 42, 0.12);
}

/* =========
   GLOBAL
   ========= */

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background: radial-gradient(circle at top, #1d2144 0, var(--bg) 40%);
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Scrollbar (subtle) */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
}

/* =========
   HEADER
   ========= */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  margin-bottom: 20px;
  background: linear-gradient(
      135deg,
      rgba(99, 102, 241, 0.18),
      rgba(14, 116, 144, 0.12)
    ),
    var(--bg-elevated);
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: var(--shadow-soft);
  position: sticky;
  top: 12px;
  z-index: 20;
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: radial-gradient(circle at 15% 15%, #e5e7eb, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: white;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.6);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent-text);
}

.brand-sub {
  font-weight: 600;
  font-size: 18px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: flex-end;
}

.tagline {
  font-size: 13px;
  color: var(--text-muted);
}

.pill {
  border-radius: var(--radius-pill);
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(15, 23, 42, 0.15);
  color: var(--accent-text);
}

.pill-outline {
  background: transparent;
}

/* =========
   LAYOUT
   ========= */

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 32%) minmax(0, 34%) minmax(0, 34%);
  gap: 18px;
  margin-top: 12px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.panel-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* =========
   CARDS & ELEMENTS
   ========= */

.card {
  background: var(--bg-elevated-soft);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 14px 14px 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.4);
}

.card-filled {
  background: radial-gradient(
      circle at top left,
      rgba(79, 70, 229, 0.2),
      transparent 55%
    ),
    var(--bg-elevated);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.card-header h3 {
  margin: 0;
  font-size: 15px;
}

.card-subheader {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 4px 0 6px;
}

.label-sm {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.value-lg {
  font-weight: 600;
  font-size: 15px;
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
}

/* =========
   FORMS
   ========= */

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.form-field label {
  font-size: 12px;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-field {
  flex: 1;
}

input[type="text"],
input[type="number"],
textarea {
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.45);
  color: var(--text);
  font-size: 13px;
  padding: 7px 9px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
    background var(--transition-fast), transform 90ms ease-out;
}

html[data-theme="light"] input[type="text"],
html[data-theme="light"] input[type="number"],
html[data-theme="light"] textarea {
  background: #f9fafb;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--ring-shadow);
  transform: translateY(-1px);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

/* =========
   BUTTONS
   ========= */

.btn {
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  background: var(--bg-elevated-soft);
  color: var(--text);
  transition: background var(--transition-fast), border-color var(--transition-fast),
    transform 90ms ease-out, box-shadow var(--transition-fast), color var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #f9fafb;
  box-shadow: 0 12px 30px rgba(55, 48, 163, 0.6);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 40px rgba(55, 48, 163, 0.75);
}

.btn-outline {
  border-color: rgba(148, 163, 184, 0.5);
  background: transparent;
}

.btn-outline:hover {
  background: rgba(15, 23, 42, 0.28);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.15);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 8px 18px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  transform: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
}

.button-row.right {
  justify-content: flex-end;
}

/* Distraction pills */
.distraction-section .pill {
  background: var(--accent-soft);
  border-color: transparent;
  font-size: 12px;
  padding: 6px 11px;
  color: var(--accent-text);
  cursor: pointer;
  transition: transform 80ms ease-out, box-shadow 120ms ease-out,
    background var(--transition-fast);
}

.distraction-section .pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.55);
}

.distraction-section .pill:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Theme toggle button */
.theme-icon {
  font-size: 15px;
}

/* =========
   SESSIONS LIST
   ========= */

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-muted);
}

html[data-theme="light"] .badge {
  background: #e5e7eb;
}

.session-list {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.session-item {
  display: flex;
  flex-direction: column;
  padding: 7px 9px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: radial-gradient(
      circle at top left,
      rgba(79, 70, 229, 0.25),
      transparent 55%
    ),
    rgba(15, 23, 42, 0.75);
  cursor: pointer;
  transition: transform 90ms ease-out, box-shadow 120ms ease-out, border-color var(--transition-fast),
    background var(--transition-fast);
}

html[data-theme="light"] .session-item {
  background: radial-gradient(
      circle at top left,
      rgba(79, 70, 229, 0.16),
      transparent 50%
    ),
    #f9fafb;
}

.session-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.session-item-title {
  font-size: 13px;
  font-weight: 600;
}

.session-item-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.session-item-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
}

html[data-theme="light"] .session-item-tag {
  background: #e5e7eb;
}

.session-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.5);
}

/* =========
   TIMER CARD
   ========= */

.timer-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timer-layout {
  display: grid;
  grid-template-columns: minmax(0, 48%) minmax(0, 52%);
  gap: 8px;
  align-items: center;
}

.timer-visual {
  display: flex;
  justify-content: center;
}

.progress-ring {
  position: relative;
  width: 160px;
  height: 160px;
}

.progress-ring__background,
.progress-ring__progress {
  fill: none;
  stroke-width: 10;
  transform-origin: center;
  transform: rotate(-90deg);
}

.progress-ring__background {
  stroke: rgba(148, 163, 184, 0.35);
}

.progress-ring__progress {
  stroke: url(#timerGradient);
  stroke-linecap: round;
  stroke-dasharray: 440; /* close to circumference of r=70 */
  stroke-dashoffset: 440;
  transition: stroke-dashoffset 250ms linear;
}

/* Provide gradient via CSS trick using filter (works fine for our purposes) */
.progress-ring svg {
  filter: drop-shadow(0 10px 25px rgba(79, 70, 229, 0.7));
}

.timer-display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#timeRemainingDisplay {
  font-size: 26px;
  font-weight: 600;
}

#timerPhaseLabel {
  margin-top: 4px;
}

.timer-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timer-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.timer-meta > div {
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

html[data-theme="light"] .timer-meta > div {
  background: #f9fafb;
}

/* =========
   DISTRACTION LIST
   ========= */

.distraction-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
  max-height: 120px;
  overflow-y: auto;
  font-size: 12px;
}

.distraction-list li {
  padding: 4px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.3);
}

.distraction-list li:last-child {
  border-bottom: none;
}

/* =========
   HISTORY TABLE
   ========= */

.history-wrapper {
  max-height: 210px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.history-table th,
.history-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.history-table th {
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.98);
  z-index: 1;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

html[data-theme="light"] .history-table th {
  background: #f3f4f6;
}

.history-table tr:last-child td {
  border-bottom: none;
}

.empty-row td {
  text-align: center;
  color: var(--text-muted);
}

/* =========
   CHART
   ========= */

.chart-wrapper {
  height: 220px;
}

/* =========
   OVERLAY (REFLECTION)
   ========= */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.overlay.hidden {
  display: none;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(14px);
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.94));
}

.overlay-content {
  position: relative;
  max-width: 520px;
  width: calc(100% - 40px);
  max-height: 80vh;
  overflow: auto;
}

.rating-row {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.rating-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

/* =========
   STATES
   ========= */

.empty-state {
  font-size: 12px;
  color: var(--text-muted);
}

/* =========
   RESPONSIVE
   ========= */

@media (max-width: 980px) {
  .layout-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 780px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .layout-grid {
    grid-template-columns: 1fr;
  }

  .timer-layout {
    grid-template-columns: 1fr;
  }

  .history-wrapper {
    max-height: 260px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding-inline: 10px;
  }

  .card {
    padding-inline: 10px;
  }
}
