/* ============================================================
   4Less Contracting – Operations Hub
   styles.css
   ============================================================ */

/* ─── CSS VARIABLES ─────────────────────────────────────── */
:root {
  --navy:        #1E3A5F;
  --navy-light:  #2A4F7E;
  --blue:        #2563EB;
  --blue-hover:  #1D4ED8;
  --blue-pale:   #EFF6FF;
  --blue-border: #BFDBFE;

  --white:       #FFFFFF;
  --gray-50:     #F9FAFB;
  --gray-100:    #F3F4F6;
  --gray-200:    #E5E7EB;
  --gray-300:    #D1D5DB;
  --gray-500:    #6B7280;
  --gray-700:    #374151;
  --gray-800:    #1F2937;
  --gray-900:    #111827;

  --green:       #16A34A;
  --green-pale:  #F0FDF4;
  --green-border:#BBF7D0;
  --red:         #DC2626;
  --red-pale:    #FEF2F2;
  --red-border:  #FECACA;
  --amber:       #D97706;
  --amber-pale:  #FFFBEB;
  --amber-border:#FDE68A;
  --orange:      #EA580C;
  --orange-pale: #FFF7ED;

  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', Consolas, monospace;

  --radius:      6px;
  --radius-lg:   10px;
  --shadow:      0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg:   0 10px 15px rgba(0,0,0,0.10), 0 4px 6px rgba(0,0,0,0.05);

  --header-h:    56px;
  --nav-h:       44px;
}

/* ─── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--gray-100); color: var(--gray-800); line-height: 1.5; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
img { display: block; max-width: 100%; }

/* ─── UTILITY ────────────────────────────────────────────── */
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-muted  { color: var(--gray-500); }
.text-sm     { font-size: 0.8rem; }
.text-xs     { font-size: 0.72rem; }
.font-medium { font-weight: 500; }
.font-bold   { font-weight: 600; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.flex { display: flex; align-items: center; }
.gap-2 { gap: 0.5rem; }
.ml-auto { margin-left: auto; }

/* ─── LOGIN ──────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
}

.login-wrap {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

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

.login-mark {
  width: 44px; height: 44px;
  background: var(--navy);
  color: var(--white);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem; letter-spacing: -0.5px;
  flex-shrink: 0;
}

.login-company { font-weight: 700; font-size: 1.05rem; color: var(--gray-900); }
.login-subtitle { font-size: 0.8rem; color: var(--gray-500); }

.login-error {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--red-pale);
  border: 1px solid var(--red-border);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.85rem;
}

/* ─── HEADER ─────────────────────────────────────────────── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--navy);
  display: flex; align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.header-brand { display: flex; align-items: center; gap: 0.6rem; }

.brand-mark {
  width: 32px; height: 32px;
  background: rgba(255,255,255,0.15);
  color: var(--white);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; letter-spacing: -0.5px;
}

.brand-name { color: var(--white); font-weight: 600; font-size: 0.95rem; }

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

.header-user { color: rgba(255,255,255,0.75); font-size: 0.85rem; }

/* ─── TAB NAVIGATION ─────────────────────────────────────── */
.tab-nav {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; z-index: 90;
  height: var(--nav-h);
  background: var(--white);
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0 1rem;
  background: none; border: none; cursor: pointer;
  font-size: 0.85rem; font-weight: 500; color: var(--gray-500);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.tab-btn:hover  { color: var(--gray-800); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-icon       { font-size: 0.9rem; }

/* ─── MAIN CONTENT ───────────────────────────────────────── */
.main-content {
  margin-top: calc(var(--header-h) + var(--nav-h));
  padding: 1.25rem;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.tab-pane { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  font-weight: 500; font-size: 0.85rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--blue);   color: var(--white); }
.btn-primary:hover { background: var(--blue-hover); }
.btn-ghost    { background: var(--white);  color: var(--gray-700); border-color: var(--gray-300); }
.btn-ghost:hover  { background: var(--gray-50); }
.btn-ghost-sm { background: transparent; color: rgba(255,255,255,0.8); border: 1px solid rgba(255,255,255,0.25); font-size: 0.8rem; padding: 0.3rem 0.7rem; border-radius: var(--radius); cursor: pointer; }
.btn-ghost-sm:hover { background: rgba(255,255,255,0.1); }
.btn-danger   { background: var(--red-pale); color: var(--red); border-color: var(--red-border); }
.btn-danger:hover { background: var(--red); color: var(--white); }
.btn-full     { width: 100%; justify-content: center; padding: 0.65rem 1rem; font-size: 0.95rem; }
.btn-sm       { padding: 0.3rem 0.65rem; font-size: 0.78rem; }

/* ─── FORM ELEMENTS ──────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: 0.82rem; font-weight: 500;
  color: var(--gray-700); margin-bottom: 0.35rem;
}
.form-group label .req { color: var(--red); margin-left: 2px; }

input[type="text"], input[type="tel"], input[type="email"],
input[type="date"], input[type="number"], input[type="url"],
input[type="password"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--gray-800);
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
textarea { min-height: 80px; resize: vertical; }

select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.2em;
  padding-right: 2rem;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-section-title {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--gray-500);
  padding: 0.75rem 0 0.4rem; border-top: 1px solid var(--gray-100);
  margin-top: 0.5rem;
}
.form-section-title:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ─── DASHBOARD ──────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.dash-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  position: relative;
  overflow: hidden;
}
.dash-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}
.dash-card:hover { box-shadow: var(--shadow-md); border-color: var(--gray-300); }

.dash-card.red::before    { background: var(--red); }
.dash-card.amber::before  { background: var(--amber); }
.dash-card.green::before  { background: var(--green); }
.dash-card.blue::before   { background: var(--blue); }
.dash-card.navy::before   { background: var(--navy); }

.card-count { font-size: 2rem; font-weight: 700; line-height: 1; }
.card-label { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.2rem; }
.card-count.red   { color: var(--red); }
.card-count.amber { color: var(--amber); }
.card-count.green { color: var(--green); }
.card-count.blue  { color: var(--blue); }
.card-count.navy  { color: var(--navy); }

.dash-section-title {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--gray-500);
  margin: 1.5rem 0 0.65rem;
}

/* ─── PAGE HEADER ────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.1rem; font-weight: 600; color: var(--gray-900); }
.page-header .actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── FILTER BAR ─────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 0.5rem; margin-bottom: 0.85rem;
  flex-wrap: wrap; align-items: center;
}
.filter-bar input[type="text"] { max-width: 220px; }
.filter-bar select { max-width: 180px; }

/* ─── TABLE ──────────────────────────────────────────────── */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
.data-table th {
  background: var(--gray-50); text-align: left;
  padding: 0.6rem 0.85rem; font-weight: 600; font-size: 0.78rem;
  color: var(--gray-600, #4B5563); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200); white-space: nowrap; user-select: none;
}
.data-table td {
  padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--gray-100);
  color: var(--gray-800); vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--blue-pale); cursor: pointer; }
.data-table .no-results td { text-align: center; color: var(--gray-500); padding: 2rem; cursor: default; }
.data-table .no-results:hover td { background: none; }

.table-actions { display: flex; gap: 0.35rem; }

/* Overflow scroll for wide tables */
.table-outer { overflow-x: auto; }

/* ─── STATUS BADGES ──────────────────────────────────────── */
.badge {
  display: inline-block; padding: 0.2rem 0.55rem;
  border-radius: 99px; font-size: 0.72rem; font-weight: 500;
  white-space: nowrap;
}

/* Urgency */
.badge-hot     { background: var(--red-pale);   color: var(--red);   border: 1px solid var(--red-border); }
.badge-high    { background: var(--orange-pale); color: var(--orange); border: 1px solid #FDBA74; }
.badge-medium  { background: var(--blue-pale);  color: var(--blue);  border: 1px solid var(--blue-border); }
.badge-low     { background: var(--gray-100);   color: var(--gray-500); border: 1px solid var(--gray-200); }

/* Pipeline stages */
.badge-new     { background: var(--gray-100);   color: var(--gray-700); border: 1px solid var(--gray-200); }
.badge-active  { background: var(--blue-pale);  color: var(--blue);  border: 1px solid var(--blue-border); }
.badge-won     { background: var(--green-pale); color: var(--green); border: 1px solid var(--green-border); }
.badge-lost    { background: var(--gray-100);   color: var(--gray-500); border: 1px solid var(--gray-200); }
.badge-warn    { background: var(--amber-pale); color: var(--amber); border: 1px solid var(--amber-border); }
.badge-danger  { background: var(--red-pale);   color: var(--red);   border: 1px solid var(--red-border); }
.badge-good    { background: var(--green-pale); color: var(--green); border: 1px solid var(--green-border); }
.badge-info    { background: var(--blue-pale);  color: var(--blue);  border: 1px solid var(--blue-border); }
.badge-neutral { background: var(--gray-100);   color: var(--gray-600, #4B5563); border: 1px solid var(--gray-200); }

/* ─── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 680px;
  box-shadow: var(--shadow-lg);
  margin: auto;
  position: relative;
}

.modal-header {
  display: flex; align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  gap: 1rem;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-close {
  margin-left: auto; background: none; border: none;
  font-size: 1.1rem; color: var(--gray-500); cursor: pointer;
  padding: 0.2rem 0.4rem; border-radius: 4px;
  transition: background 0.1s;
}
.modal-close:hover { background: var(--gray-100); }

.modal-body { padding: 1.25rem; max-height: calc(100vh - 220px); overflow-y: auto; }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.65rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── TOAST ──────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300;
  padding: 0.75rem 1.1rem;
  background: var(--gray-900); color: var(--white);
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s;
  max-width: 320px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--amber); }

/* ─── LOADING / EMPTY ────────────────────────────────────── */
.loading-spinner {
  display: flex; align-items: center; justify-content: center;
  padding: 3rem; gap: 0.75rem; color: var(--gray-500);
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--gray-200);
  border-top-color: var(--blue);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--gray-500); font-size: 0.9rem;
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }

/* ─── DETAIL DRAWER (record expanded view) ───────────────── */
.detail-row {
  display: grid; grid-template-columns: 160px 1fr;
  gap: 0.4rem 0.75rem; padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-100); font-size: 0.875rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--gray-500); font-weight: 500; font-size: 0.8rem; }
.detail-value { color: var(--gray-800); word-break: break-word; }

/* ─── SETTINGS TAB ───────────────────────────────────────── */
.settings-section { background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--gray-200); padding: 1.1rem; margin-bottom: 1rem; }
.settings-section h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.75rem; }
.settings-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.settings-tag { background: var(--gray-100); border: 1px solid var(--gray-200); border-radius: 99px; padding: 0.2rem 0.65rem; font-size: 0.8rem; color: var(--gray-700); }

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 700px) {
  .main-content { padding: 0.75rem; }
  .dash-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .card-count { font-size: 1.6rem; }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { gap: 0.4rem; }
  .filter-bar input, .filter-bar select { max-width: none; flex: 1 1 auto; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .actions { margin-left: 0; }
  .modal { margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-body { max-height: 65vh; }
  .detail-row { grid-template-columns: 1fr; gap: 0.15rem; }
  .detail-label { font-size: 0.72rem; }
  .tab-btn .tab-label { display: none; }
  .tab-btn { padding: 0 0.75rem; }
  .tab-icon { font-size: 1.1rem; }
}

@media (min-width: 701px) and (max-width: 1024px) {
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1025px) {
  .dash-grid { grid-template-columns: repeat(4, 1fr); }
}
