/* ============================================================
   Tutor Invoice System — Design System
   Palette: Warm off-white + deep slate + amber accent
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg:        #F7F5F2;
  --surface:   #FFFFFF;
  --border:    #E4E1DC;
  --border-2:  #D0CCC5;
  --text-1:    #1C1917;
  --text-2:    #57534E;
  --text-3:    #A8A29E;
  --accent:    #D97706;
  --accent-lt: #FEF3C7;
  --accent-dk: #B45309;
  --green:     #16A34A;
  --green-lt:  #DCFCE7;
  --red:       #DC2626;
  --red-lt:    #FEE2E2;
  --blue:      #2563EB;
  --blue-lt:   #DBEAFE;
  --radius:    8px;
  --radius-lg: 14px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --font:      'DM Sans', sans-serif;
  --mono:      'DM Mono', monospace;
  --sidebar:   240px;
  --transition: 180ms ease;
}

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

html { font-size: 15px; }

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

/* ---- Auth page ---- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 2rem;
}

.auth-logo .logo-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 1.1rem;
}

.auth-logo span { font-weight: 600; font-size: 1.05rem; color: var(--text-1); }

.auth-card h1 { font-size: 1.3rem; font-weight: 600; margin-bottom: .35rem; }
.auth-card p { color: var(--text-2); font-size: .9rem; margin-bottom: 1.8rem; }

/* ---- App layout ---- */
#app { display: none; }
#app.visible { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem;
}

.sidebar-logo .logo-mark {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: .9rem; flex-shrink: 0;
}

.sidebar-logo .biz-name {
  font-size: .85rem; font-weight: 600;
  color: var(--text-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-nav { flex: 1; padding: .75rem .75rem; overflow-y: auto; }

.nav-label {
  font-size: .7rem; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
  padding: .75rem .5rem .4rem;
}

.nav-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: .875rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  border: none; background: none; width: 100%; text-align: left;
}

.nav-item:hover { background: var(--bg); color: var(--text-1); }
.nav-item.active { background: var(--accent-lt); color: var(--accent-dk); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: .75rem;
  border-top: 1px solid var(--border);
}

.main {
  margin-left: var(--sidebar);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

.content { padding: 2rem; max-width: 1100px; }

/* ---- Components ---- */
/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .875rem; font-weight: 500;
  border: none; cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dk); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-2);
}
.btn-secondary:hover { background: var(--bg); color: var(--text-1); }

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

.btn-danger { background: var(--red-lt); color: var(--red); }
.btn-danger:hover { background: var(--red); color: white; }

.btn-success { background: var(--green-lt); color: var(--green); }
.btn-success:hover { background: var(--green); color: white; }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title { font-size: 1rem; font-weight: 600; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.stat-label { font-size: .78rem; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.75rem; font-weight: 600; margin: .3rem 0 .2rem; }
.stat-sub { font-size: .8rem; color: var(--text-2); }

/* Forms */
.form-group { margin-bottom: 1.1rem; }
.form-label { display: block; font-size: .83rem; font-weight: 500; color: var(--text-2); margin-bottom: .4rem; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text-1);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, .12);
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .78rem; color: var(--text-3); margin-top: .3rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  color: var(--text-1);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .55rem;
  border-radius: 4px;
  font-size: .75rem; font-weight: 600;
}

.badge-green  { background: var(--green-lt);  color: var(--green); }
.badge-red    { background: var(--red-lt);    color: var(--red); }
.badge-amber  { background: var(--accent-lt); color: var(--accent-dk); }
.badge-blue   { background: var(--blue-lt);   color: var(--blue); }
.badge-grey   { background: var(--bg);        color: var(--text-3); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: translateY(12px);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { padding: 1.5rem 1.5rem 0; display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer { padding: 0 1.5rem 1.5rem; display: flex; justify-content: flex-end; gap: .5rem; }

/* Alert / toast */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 500; display: flex; flex-direction: column; gap: .5rem;
}

.toast {
  background: var(--text-1);
  color: var(--bg);
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  min-width: 260px;
  animation: slideIn .2s ease;
}

.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--accent); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
}
.empty-state svg { width: 40px; height: 40px; margin-bottom: 1rem; opacity: .4; }
.empty-state h3 { font-size: .95rem; font-weight: 500; color: var(--text-2); margin-bottom: .4rem; }
.empty-state p { font-size: .85rem; }

/* Page sections */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 600; }
.page-header p { color: var(--text-2); font-size: .9rem; margin-top: .2rem; }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 1.25rem;
}

.search-input-wrap {
  position: relative; flex: 1; max-width: 360px;
}

.search-input-wrap svg {
  position: absolute; left: .75rem; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-3);
}

.search-input-wrap input {
  width: 100%;
  padding: .5rem .75rem .5rem 2.2rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-family: var(--font); font-size: .875rem;
  background: var(--surface); color: var(--text-1);
  outline: none;
}

.search-input-wrap input:focus { border-color: var(--accent); }

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* Checkbox */
.checkbox-group {
  display: flex; align-items: center; gap: .5rem;
  font-size: .875rem;
}

.checkbox-group input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Invoice PDF preview area */
.invoice-preview {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  font-family: var(--font);
  color: #1C1917;
  max-width: 760px;
}

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn {
  padding: .6rem 1.1rem;
  font-family: var(--font); font-size: .875rem; font-weight: 500;
  color: var(--text-2);
  border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition);
}
.tab-btn.active { color: var(--accent-dk); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text-1); }

/* Revenue chart bars */
.chart-bar-wrap { display: flex; align-items: flex-end; gap: 6px; height: 80px; }
.chart-bar { flex: 1; background: var(--accent-lt); border-radius: 4px 4px 0 0; position: relative; min-width: 20px; transition: background .2s; }
.chart-bar:hover { background: var(--accent); }
.chart-bar-label { font-size: .65rem; color: var(--text-3); text-align: center; margin-top: 4px; }

/* Responsive tweaks */
@media (max-width: 768px) {
  :root { --sidebar: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); width: 240px; }
  .main { margin-left: 0; }
  .content { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Utility */
.text-muted { color: var(--text-2); }
.text-small { font-size: .8rem; }
.text-mono  { font-family: var(--mono); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-amber { color: var(--accent); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.loading { opacity: .5; pointer-events: none; }
