/* ── Modern SaaS Design System for HabitFlow ── */
:root {
	--bg-canvas: #f8fafc;
	--bg-surface: #ffffff;
	--bg-elevated: #ffffff;
	--bg-hover: #f1f5f9;
	--text-primary: #0f172a;
	--text-muted: #475569;
	--text-subtle: #94a3b8;
	--border-default: #e2e8f0;
	--border-strong: #cbd5e1;
	--brand-50: #eef2ff;
	--brand-100: #e0e7ff;
	--brand-500: #6366f1;
	--brand-600: #4f46e5;
	--brand-700: #4338ca;
	--brand-fg: var(--brand-600);
	--brand-bg-subtle: var(--brand-50);
	--success-fg: #15803d;
	--success-bg: #dcfce7;
	--warning-fg: #a16207;
	--warning-bg: #fef9c3;
	--error-fg: #b91c1c;
	--error-bg: #fee2e2;
	--radius-sm: 4px;
	--radius-md: 6px;
	--radius-lg: 10px;
	--radius-xl: 14px;
	--radius-full: 9999px;
	--shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
	--shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px 0 rgba(15, 23, 42, 0.04);
	--shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
	--shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.03);
	--ring-focus: 0 0 0 3px rgba(79, 70, 229, 0.22);
	--ring-error: 0 0 0 3px rgba(220, 38, 38, 0.18);
	--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"],
.dark {
	--bg-canvas: #090d16;
	--bg-surface: #111827;
	--bg-elevated: #1a2234;
	--bg-hover: rgba(255, 255, 255, 0.06);
	--text-primary: #f1f5f9;
	--text-muted: #94a3b8;
	--text-subtle: #64748b;
	--border-default: #1f293d;
	--border-strong: #334155;
	--brand-50: rgba(99, 102, 241, 0.16);
	--brand-100: rgba(99, 102, 241, 0.28);
	--brand-500: #818cf8;
	--brand-600: #6366f1;
	--brand-700: #4f46e5;
	--brand-fg: #818cf8;
	--brand-bg-subtle: rgba(99, 102, 241, 0.16);
	--success-fg: #4ade80;
	--success-bg: rgba(22, 163, 74, 0.18);
	--warning-fg: #facc15;
	--warning-bg: rgba(202, 138, 4, 0.18);
	--error-fg: #f87171;
	--error-bg: rgba(220, 38, 38, 0.18);
	--shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
	--shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5);
	--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
	--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
}

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

body {
	background: var(--bg-canvas);
	color: var(--text-primary);
	font-family: var(--font-sans);
	font-size: 14px;
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;
	min-height: 100vh;
}

button, input, select, textarea {
	font-family: inherit;
	font-size: inherit;
	color: inherit;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
	outline: none;
	box-shadow: var(--ring-focus);
	border-color: var(--brand-fg) !important;
}

/* ── Shell & Topbar ── */
.app-container {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

.topbar {
	height: 56px;
	background: var(--bg-surface);
	border-bottom: 1px solid var(--border-default);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 1.25rem;
	position: sticky;
	top: 0;
	z-index: 30;
}

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

.app-logo {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-weight: 700;
	font-size: 1.05rem;
	letter-spacing: -0.02em;
	color: var(--text-primary);
}

.logo-badge {
	width: 28px;
	height: 28px;
	border-radius: var(--radius-md);
	background: linear-gradient(135deg, var(--brand-600), #8b5cf6);
	color: #ffffff;
	display: grid;
	place-items: center;
	font-weight: 800;
	font-size: 0.9rem;
	box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

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

.main-content {
	flex: 1;
	max-width: 1280px;
	width: 100%;
	margin: 0 auto;
	padding: 1.25rem 1rem 3rem;
}

@media (min-width: 768px) {
	.main-content {
		padding: 1.75rem 1.5rem 4rem;
	}
}

/* ── Segmented Nav Bar ── */
.view-nav-wrapper {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.5rem;
	flex-wrap: wrap;
}

.view-segmented {
	display: inline-flex;
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md);
	padding: 3px;
	gap: 3px;
}

.view-segment-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.4rem 0.85rem;
	font-size: 0.825rem;
	font-weight: 500;
	border-radius: var(--radius-sm);
	border: none;
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
	transition: all 0.15s ease-out;
}

.view-segment-btn:hover {
	color: var(--text-primary);
	background: var(--bg-hover);
}

.view-segment-btn.active {
	background: var(--brand-bg-subtle);
	color: var(--brand-fg);
	font-weight: 600;
}

.view-segment-count {
	font-size: 0.75rem;
	padding: 0.1rem 0.4rem;
	border-radius: var(--radius-full);
	background: rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .view-segment-count {
	background: rgba(255, 255, 255, 0.12);
}

/* ── KPI & Summary Strip ── */
.kpi-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr));
	gap: 0.875rem;
	margin-bottom: 1.5rem;
}

.kpi-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 1rem 1.15rem;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	box-shadow: var(--shadow-xs);
}

.kpi-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	color: var(--text-muted);
	font-size: 0.775rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.kpi-value-row {
	display: flex;
	align-items: baseline;
	gap: 0.5rem;
}

.kpi-value {
	font-size: 1.65rem;
	font-weight: 700;
	color: var(--text-primary);
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}

.kpi-sub {
	font-size: 0.8rem;
	color: var(--text-subtle);
}

.progress-bar-bg {
	height: 6px;
	width: 100%;
	background: var(--border-default);
	border-radius: var(--radius-full);
	overflow: hidden;
	margin-top: 0.35rem;
}

.progress-bar-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--brand-500), #10b981);
	border-radius: var(--radius-full);
	transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Week Navigation Header ── */
.week-navigator-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 0.85rem 1.15rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin-bottom: 1.25rem;
	box-shadow: var(--shadow-xs);
}

.week-nav-controls {
	display: flex;
	align-items: center;
	gap: 0.4rem;
}

.week-title-box {
	display: flex;
	flex-direction: column;
}

.week-title {
	font-size: 1rem;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.week-dates {
	font-size: 0.8rem;
	color: var(--text-muted);
}

/* ── Habit Tracker Matrix Grid ── */
.habits-table-container {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-xs);
	overflow: hidden;
	margin-bottom: 2rem;
}

.habits-table-header {
	padding: 0.85rem 1.15rem;
	border-bottom: 1px solid var(--border-default);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
}

.table-responsive-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.habits-matrix-table {
	width: 100%;
	border-collapse: collapse;
	min-width: 680px;
}

.habits-matrix-table th,
.habits-matrix-table td {
	padding: 0.75rem 0.65rem;
	text-align: center;
	border-bottom: 1px solid var(--border-default);
	vertical-align: middle;
}

.habits-matrix-table th:first-child,
.habits-matrix-table td:first-child {
	text-align: left;
	padding-left: 1.15rem;
	width: 250px;
}

.habits-matrix-table th:last-child,
.habits-matrix-table td:last-child {
	padding-right: 1.15rem;
	text-align: right;
	width: 140px;
}

.habits-matrix-table thead th {
	background: var(--bg-canvas);
	font-size: 0.775rem;
	font-weight: 600;
	color: var(--text-muted);
	letter-spacing: 0.02em;
}

.day-header-cell {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.15rem;
}

.day-header-cell.is-today {
	color: var(--brand-fg);
	font-weight: 700;
}

.day-header-num {
	width: 24px;
	height: 24px;
	display: grid;
	place-items: center;
	border-radius: var(--radius-full);
	font-size: 0.775rem;
}

.day-header-cell.is-today .day-header-num {
	background: var(--brand-fg);
	color: #ffffff;
}

.habit-row:hover {
	background: var(--bg-hover);
}

.habit-name-cell {
	display: flex;
	align-items: center;
	gap: 0.65rem;
}

.habit-color-indicator {
	width: 10px;
	height: 10px;
	border-radius: var(--radius-full);
	flex-shrink: 0;
}

.habit-title-text {
	font-weight: 600;
	font-size: 0.885rem;
	color: var(--text-primary);
}

.habit-target-pill {
	font-size: 0.725rem;
	color: var(--text-subtle);
	font-weight: 500;
}

/* ── Interactive Day Check Cell ── */
.day-toggle-btn {
	width: 34px;
	height: 34px;
	border-radius: var(--radius-md);
	border: 1px solid var(--border-default);
	background: var(--bg-surface);
	color: transparent;
	display: inline-grid;
	place-items: center;
	cursor: pointer;
	transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
	margin: 0 auto;
}

.day-toggle-btn:hover {
	border-color: var(--border-strong);
	background: var(--bg-hover);
	transform: scale(1.06);
}

.day-toggle-btn.completed {
	border-color: transparent;
	color: #ffffff;
	transform: scale(1.02);
	box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12);
}

.day-toggle-btn svg {
	width: 18px;
	height: 18px;
	stroke-width: 2.5;
}

.habit-score-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	font-size: 0.775rem;
	font-weight: 600;
	padding: 0.2rem 0.5rem;
	border-radius: var(--radius-full);
	background: var(--bg-hover);
	color: var(--text-muted);
}

.habit-score-badge.target-met {
	background: var(--success-bg);
	color: var(--success-fg);
}

/* ── To-Do List Section ── */
.tasks-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-xs);
	padding: 1.15rem;
	margin-bottom: 2rem;
}

.tasks-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 1.25rem;
	flex-wrap: wrap;
}

.filter-pills {
	display: flex;
	gap: 0.35rem;
	flex-wrap: wrap;
}

.filter-pill {
	padding: 0.3rem 0.65rem;
	font-size: 0.785rem;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border-default);
	background: var(--bg-surface);
	color: var(--text-muted);
	cursor: pointer;
	font-weight: 500;
	transition: all 0.12s;
}

.filter-pill:hover {
	color: var(--text-primary);
	border-color: var(--border-strong);
}

.filter-pill.active {
	background: var(--brand-bg-subtle);
	color: var(--brand-fg);
	border-color: var(--brand-100);
	font-weight: 600;
}

/* ── Quick Add Task Form ── */
.add-task-box {
	background: var(--bg-canvas);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md);
	padding: 0.75rem;
	margin-bottom: 1.25rem;
	display: grid;
	gap: 0.6rem;
}

.task-input-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

.task-options-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex-wrap: wrap;
}

/* ── Task Items ── */
.tasks-list {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.task-item {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.75rem 0.85rem;
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md);
	transition: all 0.15s ease-out;
}

.task-item:hover {
	border-color: var(--border-strong);
	box-shadow: var(--shadow-xs);
}

.task-item.completed {
	background: var(--bg-canvas);
	opacity: 0.75;
}

.task-left {
	display: flex;
	align-items: flex-start;
	gap: 0.65rem;
	flex: 1;
	min-width: 0;
}

.task-check-btn {
	width: 20px;
	height: 20px;
	border-radius: var(--radius-sm);
	border: 1.5px solid var(--border-strong);
	background: var(--bg-surface);
	color: transparent;
	display: grid;
	place-items: center;
	cursor: pointer;
	margin-top: 1px;
	flex-shrink: 0;
	transition: all 0.12s ease-out;
}

.task-check-btn.checked {
	background: var(--brand-600);
	border-color: var(--brand-600);
	color: #ffffff;
}

.task-body {
	flex: 1;
	min-width: 0;
}

.task-title {
	font-size: 0.9rem;
	font-weight: 500;
	color: var(--text-primary);
	word-break: break-word;
}

.task-item.completed .task-title {
	text-decoration: line-through;
	color: var(--text-muted);
}

.task-meta-row {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	margin-top: 0.25rem;
	flex-wrap: wrap;
}

.priority-tag {
	font-size: 0.7rem;
	font-weight: 600;
	padding: 0.1rem 0.4rem;
	border-radius: var(--radius-sm);
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.priority-tag.high {
	background: var(--error-bg);
	color: var(--error-fg);
}

.priority-tag.medium {
	background: var(--warning-bg);
	color: var(--warning-fg);
}

.priority-tag.low {
	background: var(--brand-bg-subtle);
	color: var(--brand-fg);
}

.due-tag {
	font-size: 0.75rem;
	color: var(--text-muted);
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
}

.due-tag.overdue {
	color: var(--error-fg);
	font-weight: 600;
}

.due-tag.today {
	color: var(--warning-fg);
	font-weight: 600;
}

.category-tag {
	font-size: 0.725rem;
	padding: 0.05rem 0.4rem;
	border-radius: var(--radius-sm);
	background: var(--bg-hover);
	color: var(--text-muted);
}

.task-actions {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	opacity: 0.8;
}

.task-item:hover .task-actions {
	opacity: 1;
}

/* ── Generic Buttons & Inputs ── */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	height: 32px;
	padding: 0 0.75rem;
	font-size: 0.825rem;
	font-weight: 500;
	border-radius: var(--radius-md);
	border: 1px solid transparent;
	background: var(--brand-600);
	color: #ffffff;
	cursor: pointer;
	transition: all 0.12s ease-out;
	white-space: nowrap;
}

.btn:hover {
	background: var(--brand-700);
}

.btn-secondary {
	background: var(--bg-surface);
	color: var(--text-primary);
	border-color: var(--border-default);
}

.btn-secondary:hover {
	background: var(--bg-hover);
	border-color: var(--border-strong);
}

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

.btn-ghost:hover {
	background: var(--bg-hover);
	color: var(--text-primary);
}

.btn-danger {
	background: var(--error-fg);
	color: #ffffff;
}

.btn-danger:hover {
	filter: brightness(0.92);
}

.btn-sm {
	height: 28px;
	padding: 0 0.55rem;
	font-size: 0.775rem;
}

.btn-icon {
	width: 32px;
	height: 32px;
	padding: 0;
}

.btn-icon-sm {
	width: 26px;
	height: 26px;
	padding: 0;
	border-radius: var(--radius-sm);
}

.input, .select, .textarea {
	height: 32px;
	padding: 0 0.65rem;
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md);
	background: var(--bg-surface);
	color: var(--text-primary);
	font-size: 0.85rem;
	transition: border-color 0.12s;
}

.textarea {
	height: auto;
	padding: 0.5rem 0.65rem;
	resize: vertical;
}

.input:focus, .select:focus, .textarea:focus {
	border-color: var(--brand-fg);
	outline: none;
}

/* ── Modal Dialogs ── */
.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.45);
	backdrop-filter: blur(2px);
	display: grid;
	place-items: center;
	z-index: 50;
	padding: 1rem;
	animation: fadeIn 0.15s ease-out;
}

.modal-card {
	background: var(--bg-elevated);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-xl);
	width: 100%;
	max-width: 480px;
	box-shadow: var(--shadow-lg);
	overflow: hidden;
	animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
	padding: 1rem 1.25rem;
	border-bottom: 1px solid var(--border-default);
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.modal-title {
	font-size: 1.05rem;
	font-weight: 600;
}

.modal-body {
	padding: 1.25rem;
	display: grid;
	gap: 1rem;
}

.modal-footer {
	padding: 0.85rem 1.25rem;
	border-top: 1px solid var(--border-default);
	background: var(--bg-canvas);
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.5rem;
}

.form-field {
	display: grid;
	gap: 0.35rem;
}

.form-label {
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--text-primary);
}

.color-picker-row {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.color-swatch-btn {
	width: 26px;
	height: 26px;
	border-radius: var(--radius-full);
	border: 2px solid transparent;
	cursor: pointer;
	transition: transform 0.12s;
}

.color-swatch-btn:hover {
	transform: scale(1.12);
}

.color-swatch-btn.selected {
	border-color: var(--text-primary);
	box-shadow: 0 0 0 2px var(--bg-surface);
}

/* ── Auth Cards ── */
.auth-wrapper {
	min-height: 80vh;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.5rem 1rem;
}

.auth-card {
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-xl);
	padding: 2rem 1.75rem;
	width: 100%;
	max-width: 400px;
	box-shadow: var(--shadow-md);
}

.auth-header {
	text-align: center;
	margin-bottom: 1.5rem;
}

.auth-header h2 {
	font-size: 1.4rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	margin-top: 0.5rem;
}

.auth-header p {
	color: var(--text-muted);
	font-size: 0.85rem;
	margin-top: 0.25rem;
}

/* ── Two Column Split for Dashboard ── */
.dashboard-columns {
	display: grid;
	grid-template-columns: 1fr;
	gap: 1.5rem;
}

@media (min-width: 1024px) {
	.dashboard-columns {
		grid-template-columns: 1.35fr 1fr;
	}
}

/* ── Today Focus Box ── */
.today-focus-card {
	background: linear-gradient(145deg, var(--bg-surface), var(--brand-bg-subtle));
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg);
	padding: 1.25rem;
	margin-bottom: 1.5rem;
	box-shadow: var(--shadow-xs);
}

.today-focus-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 1rem;
}

.today-focus-title {
	font-size: 1.05rem;
	font-weight: 700;
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

/* ── Utilities & Animations ── */
@keyframes fadeIn {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes slideUp {
	from { opacity: 0; transform: translateY(10px) scale(0.98); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

.empty-state-box {
	text-align: center;
	padding: 2.5rem 1rem;
	color: var(--text-muted);
}

.empty-state-icon {
	font-size: 2.25rem;
	margin-bottom: 0.5rem;
	color: var(--text-subtle);
}

.badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.15rem 0.5rem;
	border-radius: var(--radius-full);
	font-size: 0.75rem;
	font-weight: 500;
}

.badge-brand {
	background: var(--brand-bg-subtle);
	color: var(--brand-fg);
}

.badge-success {
	background: var(--success-bg);
	color: var(--success-fg);
}

/* Mobile responsive fixes */
@media (max-width: 640px) {
	.week-navigator-card {
		flex-direction: column;
		align-items: flex-start;
	}
	.view-nav-wrapper {
		flex-direction: column;
		align-items: stretch;
	}
	.view-segmented {
		overflow-x: auto;
		width: 100%;
	}
}
