/* =============================================
   ContratGo — Application CSS
   ============================================= */

:root {
  --green-900: #0a3d24;
  --green-800: #0f5132;
  --green-700: #166534;
  --green-600: #16a34a;
  --green-500: #22c55e;
  --green-400: #4ade80;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;
  --gold:      #f59e0b;
  --gold-light:#fef3c7;
  --gray-900:  #111827;
  --gray-800:  #1f2937;
  --gray-700:  #374151;
  --gray-600:  #4b5563;
  --gray-400:  #9ca3af;
  --gray-200:  #e5e7eb;
  --gray-100:  #f3f4f6;
  --gray-50:   #f9fafb;
  --red-600:   #dc2626;
  --red-50:    #fef2f2;
  --blue-600:  #2563eb;
  --blue-50:   #eff6ff;
  --yellow-600:#d97706;
  --yellow-50: #fffbeb;
  --white:     #ffffff;
  --sidebar-w: 240px;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.5;
}

a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- App Shell ---- */
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--green-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-logo-text { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-logo-text span { color: var(--gold); }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  padding: 12px 18px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: rgba(255,255,255,.75);
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  text-decoration: none;
}
.nav-item.active { border-left: 3px solid var(--gold); }
.nav-item svg { opacity: .8; }

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 13px;
  color: rgba(255,255,255,.5);
}
.sidebar-user-name { color: #fff; font-weight: 600; font-size: 14px; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top bar */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 17px; font-weight: 600; color: var(--gray-900); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--gray-700);
}

/* Page content */
.page-content { padding: 24px; flex: 1; }

/* Flash messages */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}
.flash-success { background: var(--green-100); color: var(--green-800); border: 1px solid var(--green-400); }
.flash-error   { background: var(--red-50);    color: var(--red-600);   border: 1px solid #fca5a5; }
.flash-info    { background: var(--blue-50);   color: var(--blue-600);  border: 1px solid #bfdbfe; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 20px; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-green { background: var(--green-100); color: var(--green-700); }
.stat-icon-gold  { background: var(--gold-light); color: var(--yellow-600); }
.stat-icon-blue  { background: var(--blue-50);    color: var(--blue-600); }
.stat-value { font-size: 22px; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--gray-600); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.btn-primary:hover { background: var(--green-800); border-color: var(--green-800); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--white); color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-100); text-decoration: none; color: var(--gray-800); }
.btn-danger { background: var(--red-50); color: var(--red-600); border-color: #fca5a5; }
.btn-danger:hover { background: #fee2e2; text-decoration: none; color: var(--red-600); }
.btn-gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn-gold:hover { background: #d97706; text-decoration: none; color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-icon { padding: 7px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 5px; }
.form-label .required { color: var(--red-600); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-900);
  background: var(--white);
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.form-control:focus { border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-50); }
.form-control::placeholder { color: var(--gray-400); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 14px;
  color: var(--gray-800);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green  { background: var(--green-100); color: var(--green-700); }
.badge-gray   { background: var(--gray-100);  color: var(--gray-600); }
.badge-blue   { background: var(--blue-50);   color: var(--blue-600); }
.badge-yellow { background: var(--yellow-50); color: var(--yellow-600); }
.badge-red    { background: var(--red-50);    color: var(--red-600); }

/* Auth layout */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  padding: 20px;
}
.auth-card {
  background: var(--white);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo-text { font-size: 26px; font-weight: 800; color: var(--green-800); }
.auth-logo-text span { color: var(--gold); }
.auth-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 4px; color: var(--gray-900); }
.auth-subtitle { font-size: 14px; color: var(--gray-600); text-align: center; margin-bottom: 24px; }
.auth-link { text-align: center; margin-top: 20px; font-size: 14px; color: var(--gray-600); }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header-title { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-header-sub { font-size: 13px; color: var(--gray-600); margin-top: 2px; }

/* Search / Filters bar */
.filters-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters-bar .form-control { max-width: 260px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-600);
}
.empty-state svg { margin: 0 auto 16px; opacity: .3; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* Document items table */
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 0; }
.items-table th {
  font-size: 12px; font-weight: 600; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 10px; border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.items-table td { padding: 9px 10px; border-bottom: 1px solid var(--gray-100); font-size: 14px; }
.items-table tr:last-child td { border-bottom: none; }
.items-table .col-num   { width: 44px; text-align: center; }
.items-table .col-qty   { width: 80px; text-align: right; }
.items-table .col-price { width: 110px; text-align: right; }
.items-table .col-total { width: 120px; text-align: right; font-weight: 600; }
.items-table .col-del   { width: 36px; text-align: center; }
.items-table tfoot td   { padding-top: 12px; font-weight: 600; border-top: 2px solid var(--gray-200); }

/* Totals block */
.totals-block { text-align: right; }
.totals-block .total-row {
  display: flex; justify-content: flex-end;
  gap: 32px; font-size: 14px; padding: 4px 0;
}
.totals-block .total-row.grand {
  font-size: 18px; font-weight: 700;
  border-top: 2px solid var(--gray-200);
  padding-top: 10px; margin-top: 6px;
  color: var(--green-800);
}
.totals-block .total-label { color: var(--gray-600); min-width: 120px; }
.totals-block .total-value { min-width: 120px; }

/* Document show */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.doc-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.doc-meta-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-400); margin-bottom: 3px; }
.doc-meta-value { font-size: 14px; color: var(--gray-800); }

/* Status change form */
.status-form { display: flex; align-items: center; gap: 8px; }

/* Profile uploads */
.upload-preview {
  width: 90px; height: 90px;
  border-radius: var(--radius);
  border: 1px dashed var(--gray-200);
  object-fit: contain;
  display: block;
  margin-bottom: 8px;
  background: var(--gray-50);
  padding: 4px;
}

/* Quick actions */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: flex; }
  .page-content { padding: 16px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .doc-meta-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 20px; }
  .topbar { padding: 0 16px; }
}

/* ---- Document create grid ---- */
.doc-create-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}
.totals-sidebar { position: sticky; top: 80px; }

/* ---- Document show ---- */
.doc-show { padding: 28px 32px; }
.doc-show-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--green-100);
}

/* ---- Item rows (dynamic) ---- */
.btn-remove-line {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.btn-remove-line:hover { color: #ef4444; background: #fef2f2; }

/* ---- Active status button ---- */
.btn-secondary-active {
  background: var(--green-50);
  border-color: var(--green-300);
  color: var(--green-700);
  font-weight: 600;
}

@media (max-width: 900px) {
  .doc-create-grid { grid-template-columns: 1fr; }
  .totals-sidebar { position: static; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filters-bar .form-control { max-width: 100%; width: 100%; }
}
