/* ─────────────────────────────────────────────
   ILANZ AMC Portal — Main Stylesheet
   ───────────────────────────────────────────── */

:root {
  --primary:      #1a4f8a;
  --primary-dark: #123a66;
  --primary-light:#e8f0fb;
  --accent:       #e87722;
  --success:      #198754;
  --warning:      #e6a817;
  --danger:       #c0392b;
  --info:         #0d6efd;
  --gray-50:      #f8f9fa;
  --gray-100:     #f1f3f5;
  --gray-200:     #e9ecef;
  --gray-400:     #ced4da;
  --gray-600:     #6c757d;
  --gray-800:     #343a40;
  --text:         #212529;
  --radius:       6px;
  --shadow:       0 1px 4px rgba(0,0,0,.10);
  --shadow-md:    0 4px 16px rgba(0,0,0,.12);
  --sidebar-w:    240px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--gray-100);
  min-height: 100vh;
}

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

/* ── Layout ─────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-logo .app-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  display: block;
}
.sidebar-logo .app-sub {
  font-size: 11px;
  color: rgba(255,255,255,.55);
  margin-top: 2px;
  display: block;
}

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.4);
  padding: 14px 18px 4px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.82);
  font-size: 13.5px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,.10);
  color: #fff;
  border-left-color: var(--accent);
  text-decoration: none;
}
.sidebar-nav a .icon { font-size: 16px; width: 18px; text-align: center; }

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

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

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-title { font-size: 17px; font-weight: 600; color: var(--primary); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 28px; flex: 1; }

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

/* ── Stat cards (dashboard) ─────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.green  { border-left-color: var(--success); }
.stat-card.amber  { border-left-color: var(--warning); }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.blue   { border-left-color: var(--info); }
.stat-card.orange { border-left-color: var(--accent); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card.green  .stat-value { color: var(--success); }
.stat-card.amber  .stat-value { color: var(--warning); }
.stat-card.red    .stat-value { color: var(--danger); }
.stat-card.blue   .stat-value { color: var(--info); }
.stat-card.orange .stat-value { color: var(--accent); }
.stat-label { font-size: 12px; color: var(--gray-600); margin-top: 4px; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #146c43; text-decoration: none; color: #fff; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #c58a00; text-decoration: none; color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #a93226; text-decoration: none; color: #fff; }
.btn-outline  { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover  { background: var(--primary-light); text-decoration: none; }
.btn-gray     { background: var(--gray-200); color: var(--gray-800); border-color: var(--gray-400); }
.btn-gray:hover     { background: var(--gray-400); text-decoration: none; color: var(--gray-800); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Forms ──────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,79,138,.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--gray-600); }

/* ── Radio/toggle groups ─────────────────────── */
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-btn input[type=radio] { display: none; }
.radio-btn label {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--gray-800);
}
.radio-btn input[type=radio]:checked + label {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

/* ── Badges / Status ─────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-open        { background: #dbeafe; color: #1e40af; }
.badge-in-progress { background: #fef3c7; color: #92400e; }
.badge-pending     { background: #ffe4e6; color: #9f1239; }
.badge-completed   { background: #dcfce7; color: #166534; }
.badge-amc         { background: #e0f2fe; color: #0369a1; }
.badge-project     { background: #f3e8ff; color: #7c3aed; }
.badge-noncontract { background: var(--gray-200); color: var(--gray-600); }
.badge-chargeable  { background: #fde68a; color: #92400e; }
.badge-noncharge   { background: #d1fae5; color: #065f46; }
.badge-onsite      { background: #dbeafe; color: #1e40af; }
.badge-remote      { background: #e0e7ff; color: #3730a3; }

/* ── Alerts / Flash ──────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* ── Search / Filter bar ─────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 14px 20px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
.filter-bar .form-group { gap: 3px; }
.filter-bar input,
.filter-bar select { padding: 7px 9px; font-size: 13px; }

/* ── Pagination ──────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; }
.pagination a,
.pagination span {
  padding: 5px 11px;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--primary);
}
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination a:hover  { background: var(--primary-light); text-decoration: none; }

/* ── Version history ─────────────────────────── */
.version-timeline { list-style: none; padding: 0; }
.version-timeline li {
  display: flex;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gray-100);
}
.version-badge {
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.version-badge.current { background: var(--accent); }
.version-info { flex: 1; }
.version-info strong { font-size: 14px; }
.version-info .meta { font-size: 12px; color: var(--gray-600); margin-top: 2px; }

/* ── Report detail view ──────────────────────── */
.report-section {
  margin-bottom: 18px;
}
.report-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-600);
  font-weight: 700;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--gray-200);
}
.report-field { display: flex; gap: 8px; margin-bottom: 8px; }
.report-field-label { font-size: 12px; color: var(--gray-600); min-width: 150px; font-weight: 600; }
.report-field-value { font-size: 13.5px; }
.report-text-block {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  min-height: 48px;
}

/* ── Login page ──────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}
.login-box {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-text { font-size: 26px; font-weight: 800; color: var(--primary); }
.login-logo .logo-sub  { font-size: 12px; color: var(--gray-600); margin-top: 4px; }

/* ── Misc ────────────────────────────────────── */
.text-muted  { color: var(--gray-600); }
.text-small  { font-size: 12px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16{ margin-top: 16px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.ml-auto { margin-left: auto; }
hr { border: none; border-top: 1px solid var(--gray-200); margin: 20px 0; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  /* ── Sidebar: hidden off-screen, slides in ── */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4,0,.2,1);
    position: fixed; top:0; left:0; bottom:0; z-index:200;
    box-shadow: 4px 0 20px rgba(0,0,0,.18);
    width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset:0; background:rgba(0,0,0,.38); z-index:199;
  }
  .sidebar-overlay.active { display: block; }

  /* ── Main layout ── */
  .main-wrap { margin-left: 0 !important; }
  .content { padding: 12px; }

  /* ── Topbar ── */
  .topbar { padding: 0 12px; height: 52px; }
  .topbar-title { font-size: 14px; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #hamburger { display: flex !important; align-items: center; justify-content: center; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 5px 8px; font-size: 12px; }

  /* ── Grids → single column ── */
  .form-grid, .form-grid-3 { grid-template-columns: 1fr !important; gap: 10px; }
  .filter-bar { flex-direction: column; gap: 10px; }
  .filter-bar select, .filter-bar input { width: 100%; }

  /* ── Cards ── */
  .card { margin-bottom: 12px; }
  .card-header { padding: 10px 12px; }
  .card-body   { padding: 12px; }

  /* ── Tables — horizontal scroll inside wrapper ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 560px; }
  /* Tables NOT inside .table-wrap also get scroll */
  .card-body > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
  thead th, tbody td { padding: 8px 10px; font-size: 12.5px; }

  /* ── Button bars ── */
  .flex.gap-8 { flex-wrap: wrap; gap: 8px; }
  .btn { white-space: nowrap; font-size: 13px; }
  .btn-sm { font-size: 11.5px; padding: 4px 8px; }

  /* ── Report view fields ── */
  .form-grid .report-field, .form-grid > div { margin-bottom: 10px; }
  .report-field { flex-direction: column; gap: 2px; }
  .report-field-label { min-width: unset; font-size: 10px; }

  /* ── Stat grid: 2 cols ── */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-card .stat-value { font-size: 22px; }

  /* ── Analytics filter/button rows ── */
  .analytics-actions { flex-direction: column; gap: 8px; }
  .analytics-actions .btn { width: 100%; justify-content: center; }

  /* ── Version timeline ── */
  .version-timeline { padding-left: 8px; }

  /* ── Acknowledgement links table ── */
  .ack-link-cell { word-break: break-all; max-width: 140px; font-size: 11px; }

  /* ── Hide less-critical columns ── */
  .hide-mobile { display: none !important; }

  /* ── Report view 2-col info → single col ── */
  .form-grid[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}

/* ── Extra small phones (<480px) ── */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr !important; }
  .stat-card .stat-value { font-size: 18px; }
  .content { padding: 8px; }
  .card-header h2 { font-size: 14px; }
  .topbar-title { font-size: 13px; }
  .btn { padding: 8px 12px; }
}

/* ── Attachment grid ─────────────────────────────────────────── */
.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.att-thumb {
  position: relative;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--gray-50);
}

.att-thumb img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.att-name {
  font-size: 10px;
  padding: 4px 6px;
  color: var(--gray-600);
  background: #fafafa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--gray-200);
}

.att-caption {
  font-size: 10px;
  padding: 2px 6px 4px;
  color: var(--primary);
  font-style: italic;
}

.att-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(192,57,43,.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background .15s;
}

.att-del:hover { background: var(--danger); }

/* ── Customer search dropdown ─────────────────────────────────── */
.dd-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
}
.dd-item:hover { background: var(--primary-light); }
.dd-item:last-child { border-bottom: none; }

/* ── Acknowledged / locked badge ─────────────────────────────── */
.badge-locked { background: #fde68a; color: #92400e; }

/* ── Report index ack column ─────────────────────────────────── */
.ack-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--success); margin-right:4px; }

/* ── Flash auto-dismiss ───────────────────────────────────────── */
@keyframes flashIn  { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }
@keyframes flashOut { from { opacity:1; } to { opacity:0; height:0; padding:0; margin:0; overflow:hidden; } }
.flash-auto { animation: flashIn .25s ease; }
.flash-auto.hiding { animation: flashOut .4s ease forwards; }

/* ── Topbar title — accent bar ───────────────────────────────── */
.topbar-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: middle;
}

/* ── Subtle input focus improvement ─────────────────────────── */
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  background: #fafcff;
}

/* ── Select arrow polish ─────────────────────────────────────── */
.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236c757d'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ── Card hover lift (non-touch only) ────────────────────────── */
@media (hover: hover) {
  .stat-card { transition: box-shadow .2s, transform .2s; }
  .stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
}

/* ── Table row action buttons — tighter on narrow ────────────── */
@media (max-width: 900px) {
  .btn-sm { padding: 3px 8px; font-size: 11px; }
}

/* ── Flatpickr theme overrides ───────────────────────────────── */
.flatpickr-calendar { font-family: 'Segoe UI', system-ui, sans-serif; border-radius: 8px; box-shadow: var(--shadow-md); border: 1px solid var(--gray-200); }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); }
.flatpickr-day:hover { background: var(--primary-light); }
.flatpickr-months .flatpickr-month,
.flatpickr-current-month { background: var(--primary); color: #fff; }
.flatpickr-weekday { color: rgba(255,255,255,.8); background: var(--primary); }
.flatpickr-time input:hover, .flatpickr-time .flatpickr-am-pm:hover,
.flatpickr-time input:focus, .flatpickr-time .flatpickr-am-pm:focus { background: var(--primary-light); }
.flatpickr-months .flatpickr-prev-month, .flatpickr-months .flatpickr-next-month { fill: #fff; }
.flatpickr-months .flatpickr-prev-month:hover svg, .flatpickr-months .flatpickr-next-month:hover svg { fill: rgba(255,255,255,.7); }
.numInputWrapper:hover { background: var(--primary-light); }
.fp-input { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E") !important; background-repeat: no-repeat !important; background-position: right 10px center !important; background-size: 14px !important; padding-right: 32px !important; appearance: none !important; }
