/* ===== ADMIN COMMON STYLES ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; color: #333; }

/* ===== HEADER ===== */
.header {
  background: linear-gradient(135deg, #7f1d1d, #991b1b, #b91c1c);
  color: white; padding: 24px 20px; text-align: center;
  position: relative;
}
.version-stamp {
  position: absolute; top: 6px; right: 10px;
  font-size: 0.6em; opacity: 0.45; font-weight: 400;
  letter-spacing: 0.3px; white-space: nowrap;
}
.header h1 { font-size: 1.8em; margin-bottom: 4px; }
.header p { opacity: 0.8; font-size: 0.9em; }
.header .admin-badge {
  display: inline-block; background: rgba(255,255,255,0.2); padding: 3px 14px;
  border-radius: 20px; font-size: 0.75em; font-weight: 700; margin-top: 8px;
  letter-spacing: 1px; text-transform: uppercase;
}
.admin-bar { font-size: 0.8em; opacity: 0.75; margin-top: 8px; }
.admin-bar a { color: #fca5a5; text-decoration: none; }
.admin-bar a:hover { text-decoration: underline; }
.admin-nav-bar {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  margin-top: 12px;
}
.admin-nav-bar a {
  display: inline-block; padding: 8px 20px; color: white; border-radius: 6px;
  text-decoration: none; font-weight: 700; font-size: 0.9em; transition: opacity 0.15s;
}
.admin-nav-bar a:hover { opacity: 0.85; }
.admin-nav-bar .nav-home { background: #2563eb; }
.admin-nav-bar .nav-admin { background: #0f3460; }
.admin-nav-bar .nav-portal { background: #065f46; }
.admin-nav-bar .nav-logout { background: #dc2626; }

/* ===== AUTH OVERLAY ===== */
.auth-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex; align-items: center; justify-content: center;
}
.auth-overlay .auth-card {
  background: white; border-radius: 16px; padding: 50px 40px; text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3); max-width: 420px; width: 90%;
}
.auth-overlay .auth-card h2 { color: #1a1a2e; margin-bottom: 8px; font-size: 1.4em; }
.auth-overlay .auth-card p { color: #666; margin-bottom: 24px; font-size: 0.95em; }
.auth-overlay .auth-card .icon { font-size: 3em; margin-bottom: 12px; }
.auth-overlay .auth-card .error-msg {
  background: #fee2e2; color: #991b1b; padding: 10px 16px; border-radius: 8px;
  font-size: 0.88em; margin-bottom: 16px; display: none;
}
.auth-divider { display: flex; align-items: center; margin: 20px 0; gap: 12px; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: #ddd; }
.auth-divider span { color: #999; font-size: 0.85em; font-weight: 500; }
.auth-input {
  width: 100%; padding: 11px 14px; border: 2px solid #ddd; border-radius: 8px;
  font-size: 0.95em; outline: none; transition: border-color 0.2s; box-sizing: border-box;
}
.auth-input:focus { border-color: #4285F4; }
.auth-form-group { margin-bottom: 12px; text-align: left; }
.auth-form-group label { display: block; font-size: 0.85em; font-weight: 600; color: #555; margin-bottom: 4px; }
.btn-login {
  width: 100%; padding: 12px; font-size: 1em; font-weight: 600; border-radius: 8px;
  cursor: pointer; border: none; background: #1a1a2e; color: white; transition: background 0.2s;
}
.btn-login:hover { background: #0f3460; }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-google {
  display: inline-flex; align-items: center; gap: 10px; padding: 12px 28px;
  font-size: 1em; font-weight: 600; border-radius: 8px; cursor: pointer;
  border: 2px solid #ddd; background: white; color: #333; transition: all 0.2s;
}
.btn-google:hover { background: #f8f8f8; border-color: #bbb; }
.btn-google:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== CONTAINER ===== */
.container { max-width: 1300px; margin: 0 auto; padding: 20px; }

/* ===== CARDS ===== */
.card {
  background: white; border-radius: 12px; padding: 24px; margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.card h2 {
  font-size: 1.2em; color: #7f1d1d; margin-bottom: 14px;
  padding-bottom: 8px; border-bottom: 2px solid #fecaca;
  display: flex; align-items: center; gap: 10px;
}
.card h2 .tag {
  font-size: 0.65em; background: #fef2f2; color: #991b1b; padding: 2px 10px;
  border-radius: 10px; font-weight: 600;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 24px; font-size: 0.9em; font-weight: 700; border-radius: 8px;
  cursor: pointer; border: none; transition: all 0.2s;
}
.btn-primary { background: #991b1b; color: white; }
.btn-primary:hover { background: #7f1d1d; }
.btn-secondary { background: #f3f4f6; color: #333; border: 1.5px solid #ddd; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-success { background: #166534; color: white; }
.btn-success:hover { background: #14532d; }

/* ===== TABLES ===== */
table { width: 100%; border-collapse: collapse; font-size: 0.88em; }
thead th {
  background: #fef2f2; color: #7f1d1d; padding: 10px 8px; text-align: left;
  font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid #fecaca; position: sticky; top: 0; z-index: 1;
}
thead th.right { text-align: right; }
tbody td { padding: 8px; border-bottom: 1px solid #f3f3f3; vertical-align: middle; }
tbody tr:hover { background: #fffbeb; }
tbody td.item-name { font-weight: 600; color: #333; }
tbody td.unit-note { font-size: 0.8em; color: #999; }

/* ===== INPUTS ===== */
.price-input {
  width: 100px; padding: 6px 8px; border: 1.5px solid #ddd; border-radius: 6px;
  font-size: 0.9em; text-align: right; transition: border-color 0.2s;
  font-family: 'Consolas', 'Courier New', monospace;
}
.price-input:focus { border-color: #991b1b; outline: none; background: #fffbeb; }
.price-input.changed { border-color: #f59e0b; background: #fffbeb; }
.markup-input {
  width: 70px; padding: 6px 8px; border: 1.5px solid #ddd; border-radius: 6px;
  font-size: 0.9em; text-align: right; font-family: 'Consolas', 'Courier New', monospace;
}
.markup-input:focus { border-color: #991b1b; outline: none; background: #fffbeb; }
.computed {
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 700; color: #166534; text-align: right;
}

/* ===== LABOR GRID ===== */
.labor-table th, .labor-table td { text-align: center; padding: 6px 4px; }
.labor-table td input {
  width: 75px; padding: 5px 4px; border: 1.5px solid #ddd; border-radius: 5px;
  font-size: 0.85em; text-align: center; font-family: 'Consolas', 'Courier New', monospace;
}
.labor-table td input:focus { border-color: #991b1b; outline: none; background: #fffbeb; }
.labor-table .pitch-label { font-weight: 700; background: #fef2f2; color: #7f1d1d; }

/* ===== STATUS ===== */
.status-msg { font-size: 0.85em; color: #166534; font-weight: 600; margin-left: auto; opacity: 0; transition: opacity 0.3s; }
.status-msg.show { opacity: 1; }
.info-text { font-size: 0.82em; color: #777; line-height: 1.5; margin-bottom: 12px; }

/* ===== FORMULA / REFERENCE ===== */
.formula { font-size: 0.75em; color: #999; font-style: italic; }
.formula-block {
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 12px 16px; font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.88em; margin: 8px 0; color: #334155; line-height: 1.6;
}
.ref-value { font-weight: 700; color: #166534; }
.ref-section { margin-bottom: 20px; }
.ref-section h3 { font-size: 1em; color: #7f1d1d; margin-bottom: 6px; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.85em; margin: 8px 0; }
.ref-table th { background: #fef2f2; color: #7f1d1d; padding: 6px 8px; text-align: left; font-size: 0.85em; }
.ref-table td { padding: 5px 8px; border-bottom: 1px solid #f0f0f0; }
.ref-table td.right { text-align: right; font-family: 'Consolas', monospace; }

/* ===== DESCRIPTION FIELDS ===== */
.desc-field { margin-bottom: 20px; }
.desc-field label { font-weight: 700; font-size: 0.9em; color: #7f1d1d; display: block; margin-bottom: 6px; }
.desc-field .desc-hint { font-size: 0.8em; color: #999; margin-bottom: 6px; }
.desc-field textarea {
  width: 100%; padding: 10px; border: 1.5px solid #ddd; border-radius: 8px;
  font-family: 'Segoe UI', sans-serif; font-size: 0.9em; resize: vertical; transition: border-color 0.2s;
}
.desc-field textarea:focus { border-color: #991b1b; outline: none; }

/* ===== BADGES ===== */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 0.78em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-denied { background: #fee2e2; color: #991b1b; }
.pending-count {
  display: inline-block; background: #fef3c7; color: #92400e; font-size: 0.7em;
  padding: 1px 8px; border-radius: 10px; font-weight: 700; margin-left: 6px; vertical-align: middle;
}

/* ===== CONTRACTOR TABLE ===== */
.contractor-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-btn {
  padding: 6px 16px; font-size: 0.85em; font-weight: 600; border-radius: 20px;
  cursor: pointer; border: 1.5px solid #ddd; background: white; color: #555; transition: all 0.2s;
}
.filter-btn.active { background: #991b1b; color: white; border-color: #991b1b; }
.filter-btn:hover:not(.active) { background: #f3f4f6; }
.contractor-actions button {
  padding: 5px 14px; font-size: 0.8em; font-weight: 600; border-radius: 6px;
  cursor: pointer; border: none; transition: all 0.2s; margin: 2px;
}
.btn-approve { background: #d1fae5; color: #065f46; }
.btn-approve:hover { background: #a7f3d0; }
.btn-deny { background: #fee2e2; color: #991b1b; }
.btn-deny:hover { background: #fecaca; }
.btn-revoke { background: #f3f4f6; color: #666; }
.btn-revoke:hover { background: #e5e7eb; }
.btn-delete {
  padding: 5px 14px; font-size: 0.8em; font-weight: 600; border-radius: 6px;
  cursor: pointer; border: none; background: #fee2e2; color: #991b1b; transition: all 0.2s; margin: 2px;
}
.btn-delete:hover { background: #fecaca; }
.btn-admin-report {
  padding: 5px 14px; font-size: 0.8em; font-weight: 600; border-radius: 6px;
  cursor: pointer; border: none; background: #dbeafe; color: #1e40af; transition: all 0.2s; margin: 2px;
}
.btn-admin-report:hover { background: #bfdbfe; }
.btn-financial-report {
  padding: 5px 14px; font-size: 0.8em; font-weight: 600; border-radius: 6px;
  cursor: pointer; border: none; background: #d1fae5; color: #065f46; transition: all 0.2s; margin: 2px;
}
.btn-financial-report:hover { background: #a7f3d0; }
.no-contractors { text-align: center; padding: 40px; color: #999; font-size: 0.95em; }

/* ===== ESTIMATES ===== */
.estimate-row-clickable { cursor: pointer; }
.estimate-row-clickable:hover { background: #fef2f2 !important; }
.estimate-total {
  font-weight: 700; color: #166534;
  font-family: 'Consolas', 'Courier New', monospace;
}
.estimate-detail {
  background: #fafbfc; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 16px 18px; margin: 8px 0;
}
.estimate-detail h4 {
  font-size: 0.95em; color: #7f1d1d; margin-bottom: 8px;
  border-bottom: 1px solid #fecaca; padding-bottom: 4px;
}
/* Compact grouped sections */
.ed-section { margin-bottom: 10px; }
.ed-section-title {
  font-size: 0.7em; font-weight: 700; color: #991b1b;
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 4px; padding-bottom: 2px;
  border-bottom: 1px solid #fecaca;
}
.ed-grid { display: grid; gap: 2px 10px; font-size: 0.82em; }
.ed-grid-4 { grid-template-columns: repeat(4, 1fr); }
.ed-grid-5 { grid-template-columns: repeat(5, 1fr); }
.ed-grid-3 { grid-template-columns: repeat(3, 1fr); }
.ed-cell { padding: 2px 0; }
.ed-cell .ed-label { font-size: 0.75em; color: #999; font-weight: 600; line-height: 1.2; }
.ed-cell .ed-value { color: #333; font-weight: 500; }
.ed-row { display: flex; gap: 20px; }
.ed-row > .ed-section { flex: 1; min-width: 0; }
.ed-total {
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px;
  padding: 6px 12px; margin-top: 4px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 0.92em;
}
.ed-total .ed-total-label { color: #333; }
.ed-total .ed-total-amount { color: #166534; font-size: 1.1em; font-family: 'Consolas', 'Courier New', monospace; }
.ed-notes {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px;
  padding: 6px 10px; font-size: 0.82em; margin-top: 6px; white-space: pre-wrap;
}
.ed-notes strong { font-size: 0.85em; color: #92400e; display: block; margin-bottom: 2px; }
.estimate-attachments { margin-top: 12px; padding-top: 10px; border-top: 1px solid #e5e7eb; }
.estimate-attachments h5 { font-size: 0.88em; color: #7f1d1d; margin-bottom: 8px; }
.estimate-attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.estimate-attach-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: white; border-radius: 6px; border: 1px solid #e5e7eb;
  font-size: 0.82em; text-decoration: none; color: #333; transition: all 0.2s;
}
.estimate-attach-item:hover { border-color: #991b1b; background: #fef2f2; }
.estimate-attach-item .ea-icon { font-size: 1.2em; flex-shrink: 0; }
.estimate-attach-item .ea-info { flex: 1; overflow: hidden; }
.estimate-attach-item .ea-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.estimate-attach-item .ea-meta { font-size: 0.85em; color: #999; }
.estimate-attach-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; flex-shrink: 0; border: 1px solid #e5e7eb; }
.estimate-filters { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.estimate-filters input {
  padding: 8px 12px; border: 1.5px solid #ddd; border-radius: 8px;
  font-size: 0.88em; width: 240px;
}
.estimate-filters input:focus { border-color: #991b1b; outline: none; }
.company-group { margin-bottom: 8px; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }
.company-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #fef2f2; cursor: pointer;
  font-weight: 700; color: #7f1d1d; font-size: 0.95em;
  transition: background 0.2s; user-select: none;
}
.company-header:hover { background: #fecaca; }
.company-header .company-count {
  font-size: 0.8em; font-weight: 600; color: #991b1b;
  background: white; padding: 2px 10px; border-radius: 10px;
}
.company-header .expand-icon { font-size: 0.8em; margin-right: 8px; transition: transform 0.2s; }
.company-header.open .expand-icon { transform: rotate(90deg); }
.company-estimates { display: none; }
.company-estimates.open { display: block; }
.estimate-pagination {
  display: flex; justify-content: center; gap: 8px; margin-top: 16px; align-items: center;
}
.estimate-pagination button {
  padding: 6px 14px; font-size: 0.85em; border: 1.5px solid #ddd;
  border-radius: 6px; background: white; cursor: pointer;
}
.estimate-pagination button:hover { background: #fef2f2; }
.estimate-pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== TAB ACTIONS ===== */
.tab-actions {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-top: 16px; padding-top: 16px; border-top: 2px solid #fecaca;
}

/* ===== ACTION BAR ===== */
.action-bar {
  position: sticky; bottom: 0; background: white; padding: 15px 24px;
  border-top: 2px solid #fecaca; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08); border-radius: 12px 12px 0 0;
  z-index: 10;
}

/* ===== BACK BUTTON ===== */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: #fca5a5; text-decoration: none; font-size: 0.85em; font-weight: 600;
  margin-top: 6px;
}
.back-link:hover { text-decoration: underline; color: white; }

/* ===== FOOTER ===== */
.footer {
  text-align: center; padding: 30px 20px; font-size: 0.82em; color: #999;
  border-top: 1px solid #e5e7eb; margin-top: 40px;
}
.footer a { color: #7f1d1d; text-decoration: none; }

/* ===== HUB MENU GRID ===== */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}
.menu-card {
  background: white; border-radius: 14px; padding: 32px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  text-align: center; transition: all 0.25s; position: relative;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; text-decoration: none; color: inherit;
  border: 2px solid transparent;
}
.menu-card:hover { transform: translateY(-4px); box-shadow: 0 8px 30px rgba(0,0,0,0.12); border-color: #991b1b; }
.menu-card .card-icon { font-size: 2.8em; margin-bottom: 14px; }
.menu-card h3 { font-size: 1.15em; color: #1a1a2e; margin-bottom: 8px; }
.menu-card p { font-size: 0.88em; color: #777; line-height: 1.5; margin-bottom: 16px; flex-grow: 1; }
.menu-card .card-btn {
  padding: 10px 28px; border-radius: 8px; font-size: 0.9em; font-weight: 700;
  border: none; cursor: pointer; transition: all 0.2s;
}
.card-btn-primary { background: #991b1b; color: white; }
.card-btn-primary:hover { background: #7f1d1d; }
.card-btn-blue { background: #1e40af; color: white; }
.card-btn-blue:hover { background: #1e3a8a; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .price-input { width: 80px; }
  .labor-table td input { width: 60px; }
  .ed-grid-4, .ed-grid-5, .ed-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .ed-row { flex-direction: column; gap: 0; }
  .estimate-filters input { width: 100%; }
  .estimate-filters { flex-direction: column; gap: 8px; }
  .tab-actions { flex-direction: column; gap: 8px; }
  .tab-actions .btn { width: 100%; text-align: center; }
}
@media (max-width: 600px) {
  .header { padding: 18px 14px; }
  .header h1 { font-size: 1.3em; }
  .header p { font-size: 0.8em; }
  .header .admin-badge { font-size: 0.65em; padding: 2px 10px; }
  .admin-nav-bar { gap: 6px; }
  .admin-nav-bar a { padding: 7px 12px; font-size: 0.78em; }
  .menu-grid { grid-template-columns: 1fr; }
  .menu-card { padding: 24px 20px; }
  .container { padding: 10px; }
  .card { padding: 16px; margin-bottom: 14px; }
  .card h2 { font-size: 1.05em; }
  /* Tables — horizontal scroll on mobile */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
  table { min-width: 600px; }
  thead th { padding: 8px 6px; font-size: 0.72em; white-space: nowrap; }
  tbody td { padding: 6px; font-size: 0.82em; }
  /* Buttons */
  .btn { padding: 10px 16px; font-size: 0.85em; width: 100%; text-align: center; }
  .btn-admin-report, .btn-financial-report, .btn-delete { font-size: 0.75em; padding: 6px 10px; }
  /* Action bar */
  .action-bar { padding: 12px 16px; flex-wrap: wrap; }
  .action-bar .btn { flex: 1; min-width: 0; }
  /* Estimate detail */
  .estimate-detail { padding: 12px; }
  .ed-grid-4, .ed-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .ed-grid-3 { grid-template-columns: 1fr; }
  .estimate-attach-grid { grid-template-columns: 1fr; }
  /* Inputs */
  .price-input { width: 70px; font-size: 0.85em; }
  .markup-input { width: 60px; font-size: 0.85em; }
  .labor-table td input { width: 50px; font-size: 0.8em; }
  /* Company groups */
  .company-header { padding: 10px 12px; font-size: 0.88em; }
  /* Auth */
  .auth-overlay .auth-card { padding: 30px 24px; }
  /* Contractor filters */
  .contractor-filters { gap: 6px; }
  .filter-btn { padding: 5px 12px; font-size: 0.8em; }
  /* Version stamp */
  .version-stamp { font-size: 0.5em; top: 4px; right: 6px; }
}
@media print {
  .action-bar { display: none; }
  .header { padding: 15px; }
  .price-input, .markup-input, .labor-table td input { border: 1px solid #ccc; }
  .auth-overlay { display: none; }
}
