:root {
  /* Match the dark, flat look of the image */
  --bg-primary: #0a0a0a;
  --bg-secondary: #0a0a0a;
  --bg-row-hover: #141414;
  
  --text-primary: #ffffff;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;

  --accent-color: #3b82f6; /* Blue for the logo */
  --success-color: #10b981; /* Green for checkmark */
  
  --border-color: #1a1a1a;
  --border-subtle: #171717;

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Common UI Elements */
button {
  background: none; border: none; cursor: pointer;
  font-family: var(--font-family);
  color: var(--text-primary);
  transition: all 0.2s;
}

input, textarea {
  font-family: var(--font-family);
  background: transparent;
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
}
input:focus, textarea:focus { outline: none; }

.dark-input {
  background: #1a1a1a;
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
}

/* Header matching the image */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

.header-left { display: flex; align-items: center; gap: 0.75rem; }

.app-logo {
  background-color: var(--accent-color);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.app-title-group { display: flex; flex-direction: column; }

.app-title {
  font-size: 1rem; font-weight: 600; line-height: 1.2;
}

.user-status {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.75rem; color: var(--text-muted);
}
.status-dot {
  width: 6px; height: 6px;
  background-color: var(--accent-color);
  border-radius: 50%;
}
.btn-text-small {
  color: var(--text-muted); font-size: 0.75rem;
}
.btn-text-small:hover { color: var(--text-primary); }

.header-right { display: flex; align-items: center; gap: 1rem; position: relative; }

.btn-todo {
  background-color: #1a1a1a;
  color: #fff;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; gap: 0.4rem;
  position: relative;
}
.btn-todo:hover {
  background-color: #252525;
}
.todo-badge {
  position: absolute;
  top: -6px; right: -6px;
  background-color: var(--accent-color);
  color: white;
  width: 16px; height: 16px;
  border-radius: 50%;
  font-size: 0.6rem; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
}

/* Main Tracker Grid */
.main-content {
  flex: 1; display: flex; flex-direction: column;
}

.tracker-wrapper {
  overflow-x: auto;
  flex: 1;
}

.tracker-grid {
  display: grid;
  /* Will be given dynamic columns: 1 for DAY, N for habits, etc */
  width: 100%;
  min-width: 800px;
}

.grid-cell {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center;
}

/* Header texts */
.grid-header-row .grid-cell {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  border-bottom: 1px solid #1f1f1f;
}

.day-column {
  width: 100px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Allow habit names to skip capitalization and wrap properly */
.grid-header-row .habit-column-header {
  font-weight: 500;
  color: var(--text-primary);
  text-transform: none !important;
  font-size: 0.8rem;
  display: flex; gap: 4px; align-items: center;
}

.habit-column-header span {
  width: 100%;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.3;
  min-width: 0;
}

/* The add habit header item */
.add-habit-btn {
  color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
  font-size: 0.8rem; font-weight: 500;
}
.add-habit-btn:hover { color: var(--text-primary); }

.habit-column-header {
  position: relative;
}
.habit-header-controls {
  display: flex; gap: 2px; opacity: 0; transition: opacity 0.2s; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
}
.habit-column-header:hover .habit-header-controls {
  opacity: 1;
}
.habit-action-btn {
  background: #1a1a1a; color: var(--text-muted); border: 1px solid var(--border-color); cursor: pointer; padding: 2px; display: inline-flex; align-items: center; border-radius: 4px;
}
.habit-action-btn:hover { color: var(--text-primary); border-color: #3f3f46; }
.habit-action-btn.delete:hover { border-color: #ef4444; color: #ef4444; }

.add-habit-form-inline {
  display: flex; align-items: center; gap: 4px; border: 1px solid var(--border-color); border-radius: 4px; padding:2px; background:var(--bg-primary);
}
.add-habit-form-inline input {
  padding: 2px 4px; font-size: 0.8rem; width: 100px;
}

/* Rows hover */
.grid-row { display: contents; }
.grid-row > .grid-cell {
  transition: background 0.1s;
}
.grid-row:hover > .grid-cell {
  background: var(--bg-row-hover);
}
.grid-header-row:hover > .grid-cell {
  background: transparent;
}

/* Circle Toggles */
.toggle-wrapper {
  display: flex; justify-content: center; width: 100%;
}
.toggle-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid #3f3f46;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.toggle-btn:hover { border-color: #52525b; }
.toggle-btn.state-done {
  border-color: var(--success-color);
  color: var(--success-color);
}
.toggle-btn.state-done svg {
  width: 14px; height: 14px;
}
.toggle-btn.state-missed {
  border-color: #ef4444; color: #ef4444;
}

/* Progress Ring Chart (Doughnut style) */
.progress-ring {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  -webkit-mask: radial-gradient(transparent 55%, black 56%);
  mask: radial-gradient(transparent 55%, black 56%);
  flex-shrink: 0;
}

/* Daily Details Inputs */
.details-input {
  width: 100%;
  padding: 0.8rem 0.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-left: 1px solid transparent;
  background: transparent;
  border: none;
  font-family: var(--font-family);
  resize: none;
  overflow: hidden;
  min-height: 48px;
  line-height: 1.5;
  border-radius: 4px;
}
.details-input:hover, .details-input:focus {
  background: rgba(255,255,255,0.02);
  color: var(--text-primary);
  outline: none;
}

.details-column {
  flex: 1; min-width: 300px;
}

.btn-icon {
  background: transparent; padding: 4px; display: inline-flex; align-items:center;
}
.btn-icon:hover { background: #2a2a2a; border-radius: 4px; }
.btn-primary {
  background: var(--accent-color); color: #fff; padding: 0.5rem 1rem; border-radius: 4px;
}

/* Auth Modal */
.auth-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.auth-overlay.open { opacity: 1; pointer-events: all; }
.auth-modal {
  background: var(--bg-secondary); padding: 2rem; border-radius: 8px; width: 100%; max-width: 500px; border: 1px solid var(--border-color);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5); display: flex; flex-direction: column; gap: 1rem;
  max-height: 85vh; overflow-y: auto;
}
.auth-modal h2 { text-align: center; font-size: 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form input { padding: 0.8rem; border: 1px solid var(--border-color); background: var(--bg-primary); }
.auth-error { color: #ef4444; font-size: 0.85rem; text-align: center; display: none; background: rgba(239, 68, 68, 0.1); padding: 0.5rem; border-radius: 4px;}
.auth-divider { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin: 0.5rem 0; }
.btn-secondary { background: #1a1a1a; border: 1px solid var(--border-color); color: var(--text-primary); padding: 0.8rem; border-radius: 4px; display:flex; align-items:center; justify-content:center; gap: 8px;}
.btn-secondary:hover { background: #252525; }

/* Sidebar overlay */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: all; }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; right: -400px; width: 400px; max-width: 100%; height: 100vh;
  background: var(--bg-secondary); border-left: 1px solid var(--border-color);
  z-index: 50; transition: right 0.3s, left 0.3s; display: flex; flex-direction: column;
}
.sidebar.open { right: 0; }
.sidebar.sidebar-left {
  right: auto; left: -400px; border-left: none; border-right: 1px solid var(--border-color);
}
.sidebar.sidebar-left.open { left: 0; }

.sidebar-header {
  padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center;
}
.sidebar-content {
  padding: 1.5rem; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem;
}

/* Stats Cards */
.stat-card {
  background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 8px; padding: 1rem;
}
.stat-card-title { font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin-bottom: 0.5rem; }
.stat-card-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); }
.stat-flex { display: flex; gap: 1rem; }
.stat-flex > div { flex: 1; }

.habit-bar-wrap { margin-bottom: 1rem; }
.habit-bar-header { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.4rem; }
.habit-bar-bg { width: 100%; height: 8px; background: #27272a; border-radius: 4px; overflow: hidden; position: relative; }
.habit-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease-out; }

.todo-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem;
  background: #1a1a1a; border-radius: 4px;
}
.todo-checkbox {
  width: 24px; height: 24px; border-radius: 6px; border: 2px solid #52525b; appearance: none;
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
.todo-checkbox:hover {
  border-color: var(--accent-color); background: rgba(255,255,255,0.05);
}
.todo-checkbox:checked {
  background: var(--accent-color); border-color: var(--accent-color); position: relative;
}
.todo-checkbox:checked::after {
  content: '✓'; position: absolute; color: white; font-size: 14px; top: 50%; left: 50%; transform: translate(-50%, -50%); font-weight: bold;
}
.todo-text { flex: 1; color: var(--text-primary); font-size: 0.9rem;}
.todo-item.completed .todo-text { text-decoration: line-through; color: var(--text-muted); }

.add-todo-form { display: flex; gap: 0.5rem; }
.add-todo-form input { flex: 1; }
