/* Reset & Variables */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:    #002B7F;
  --brand-dk: #001e5c;
  --accent:   #00AEEF;
  --accent-dk:#0090c8;
  --success:  #15803d;
  --warn:     #b45309;
  --error:    #b91c1c;
  --bg:       #f0f4f9;
  --surface:  #ffffff;
  --border:   #dde3ee;
  --text:     #0f1c35;
  --muted:    #5a6a85;
  --radius:   8px;
  --shadow:   0 2px 8px rgba(0,43,127,.08), 0 6px 24px rgba(0,43,127,.07);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* Nav */
nav {
  background: var(--nav-bg, #ddeefa);
  color: var(--brand);
  padding: 0 2rem;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0,43,127,.12);
  border-bottom: 2px solid var(--accent);
}
.nav-brand { display: flex; align-items: center; gap: 0; }
.nav-brand img { display: block; }
.nav-links { display: flex; align-items: center; gap: 1.2rem; }
.nav-links a {
  color: var(--brand); text-decoration: none; font-size: 13px;
  padding: .3rem .65rem; border-radius: 6px; transition: all .15s; font-weight: 500;
}
.nav-links a:hover { color: var(--accent); background: rgba(0,174,239,.18); }
.nav-user {
  font-size: 12px; background: rgba(0,174,239,.2); color: var(--brand);
  padding: 3px 12px; border-radius: 20px; font-weight: 600;
  border: 1px solid rgba(0,174,239,.45);
}

/* Nav icon buttons */
.nav-icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: var(--brand); background: transparent; border: none; cursor: pointer;
  text-decoration: none; transition: all .15s; padding: 0;
}
.nav-icon-btn:hover { color: var(--accent); background: rgba(0,174,239,.18); }

/* Settings dropdown */
.nav-dropdown { position: relative; display: flex; align-items: center; }
.nav-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 999; padding: .3rem .4rem;
  flex-direction: row; gap: .2rem;
}
.nav-dropdown:hover .nav-dropdown-menu { display: flex; }
.nav-dropdown-menu a { padding: 0; }

/* Main — full width so wide table fits */
main { width: 100%; padding: 1.5rem 1.5rem; }

/* Alerts */
.alert {
  padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: 14px; border-left: 4px solid;
}
.alert-success { background: #f0fdf4; border-color: var(--success); color: var(--success); }
.alert-warning { background: #fffbeb; border-color: var(--warn); color: var(--warn); }
.alert-error   { background: #fef2f2; border-color: var(--error); color: var(--error); }

/* Buttons */
.btn-primary {
  background: var(--brand); color: #fff; padding: .55rem 1.2rem;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px;
  text-decoration: none; display: inline-block; font-weight: 500;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dk); }
.btn-secondary {
  background: transparent; color: var(--muted); padding: .55rem 1.2rem;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
  font-size: 14px; text-decoration: none; display: inline-block;
}
.btn-secondary:hover { background: var(--bg); }
.btn-full { width: 100%; padding: .7rem; font-size: 15px; margin-top: .5rem; }
.btn-sm {
  font-size: 11px; padding: .25rem .6rem; border-radius: 5px;
  background: var(--brand); color: #fff; text-decoration: none;
  border: none; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn-warn { background: var(--warn); }

/* Auth */
.auth-wrap { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 2.5rem 2rem; width: 100%; max-width: 380px; box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { font-size: 42px; margin-bottom: .5rem; }
.auth-card h1 { font-size: 20px; margin-bottom: .3rem; }
.auth-sub { color: var(--muted); font-size: 14px; margin-bottom: 1.5rem; }
.auth-card label { display: block; text-align: left; font-size: 13px; font-weight: 600;
                   margin-bottom: 4px; margin-top: 1rem; }
.auth-card input { width: 100%; padding: .6rem .8rem; border: 1px solid var(--border);
                   border-radius: var(--radius); font-size: 14px; }
.auth-card input:focus { outline: none; border-color: var(--accent);
                         box-shadow: 0 0 0 3px rgba(0,174,239,.18); }

/* Page Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-header h2 { font-size: 20px; }

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  width: 100%;
}
table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
thead tr { background: var(--bg); }
th {
  padding: .45rem .6rem; text-align: left; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
code { font-family: monospace; font-size: 11px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* Badge */
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.badge-admin    { background: #dbeafe; color: #1e40af; }
.badge-engineer { background: #dcfce7; color: #166534; }
.badge-warn     { background: #fef3c7; color: #92400e; }

/* Form */
.form-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
             padding: 2rem; box-shadow: var(--shadow); max-width: 800px; }
.form-narrow { max-width: 480px; }
.form-sub { color: var(--muted); font-size: 14px; margin-bottom: 1.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: .75rem; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .optional { font-weight: 400; color: var(--muted); }
.field .field-hint { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select {
  padding: .55rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--surface);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,174,239,.15);
}
.field textarea { resize: vertical; line-height: 1.6; }
.form-actions { display: flex; gap: 1rem; justify-content: flex-end; margin-top: 1.5rem; }

/* Empty State */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-state p { margin-bottom: 1rem; }

/* Stats Bar */
.stats-bar {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
  align-items: stretch;
}
.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem 1rem;
  min-width: 100px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 20px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing:.04em; margin-top:2px; }

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: .6rem 1rem;
}
.filter-left { flex: 1; min-width: 0; }
.filter-right { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }

/* Tabs */
.tab-group { display: flex; flex-wrap: wrap; gap: .3rem; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  transition: all .15s;
}
.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Filter Controls */
.filter-select {
  padding: .3rem .5rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 12px; background: var(--surface);
}
.filter-search {
  padding: .3rem .5rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 12px; background: var(--surface);
  width: 160px;
}

/* Inline Edit */
.inline-edit {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 11px;
  background: transparent;
  color: var(--text);
  width: 65px;
}
.inline-edit:hover { border-color: var(--border); }
.inline-edit:focus { outline: none; border-color: var(--accent); background: var(--surface); }

/* Status Select */
.status-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 2px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg);
  cursor: pointer;
  color: var(--muted);
  max-width: 80px;
}
.status-select.status-green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.status-select.status-blue  { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.status-select.status-red   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* Client Badge */
.client-badge {
  display: inline-block; font-size: 11px; padding: 1px 6px;
  border-radius: 4px; background: #e6f5fd; color: #0070a8; font-weight: 500;
}

/* Time small */
.time-small { font-size: 10px; color: var(--muted); }

/* Work Item Rows */
.work-item-header {
  display: grid;
  grid-template-columns: 22px 1fr 120px 90px 90px 60px 28px;
  gap: .4rem;
  padding: 0 0 4px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: .35rem;
}
.work-item-header span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.wh-num, .wh-del { text-align: center; }

.work-item-row {
  display: grid;
  grid-template-columns: 22px 1fr 120px 90px 90px 60px 28px;
  gap: .4rem;
  align-items: center;
  margin-bottom: .35rem;
}
.work-item-num {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}
.work-item-row input[type="text"],
.work-item-row input[type="date"],
.work-item-row input[type="time"] {
  width: 100%;
  padding: .38rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}
.work-item-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,174,239,.15);
}
.item-dur {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  text-align: center;
}
.work-item-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
  transition: all .15s;
}
.work-item-remove:hover { background: #fee2e2; border-color: #fca5a5; color: var(--error); }

.btn-add-item {
  margin-top: .4rem;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: .4rem 1rem;
  width: 100%;
  transition: all .15s;
}
.btn-add-item:hover { background: #e6f5fd; border-color: var(--accent); }

.work-summary {
  margin-top: .6rem;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-box {
  background: var(--surface); border-radius: 12px; width: 100%;
  max-width: 560px; box-shadow: 0 8px 40px rgba(0,0,0,.2);
  display: flex; flex-direction: column; max-height: 90vh;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); line-height: 1;
}
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: .75rem 1.25rem; border-top: 1px solid var(--border);
  display: flex; gap: .75rem; justify-content: flex-end;
}

/* Export button */
.btn-export {
  background: #00AEEF; color: #fff; padding: .55rem 1.2rem;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px;
  font-weight: 500; transition: background .15s; display: inline-block;
  text-decoration: none; white-space: nowrap;
}
.btn-export:hover { background: #0090c8; }

/* Small icon button (PDF, regen, delete in table rows) */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; flex-shrink: 0;
  background: #00AEEF; color: #fff;
  border: none; border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
  transition: background .15s;
}
.btn-icon:hover { background: #0090c8; }
.btn-icon.btn-icon-danger:hover { background: #dc2626; }

/* Outlook button */
.btn-outlook {
  background: #0078d4; color: #fff; padding: .55rem 1.2rem;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px;
  text-decoration: none; display: inline-block; font-weight: 500;
  transition: background .15s;
}
.btn-outlook:hover { background: #005fa3; }

/* Delete button */
.btn-delete {
  font-size: 11px; padding: .22rem .5rem; border-radius: 5px;
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  cursor: pointer; font-weight: 500; transition: all .15s;
}
.btn-delete:hover { background: #fee2e2; border-color: #fca5a5; color: var(--error); }

/* Overdue row */
tr.overdue td { background: #fffbeb !important; }
tr.overdue td:first-child { border-left: 3px solid var(--warn); }
tr.overdue:hover td { background: #fef9e0 !important; }

/* To field in modal */
.modal-to-row {
  display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem;
}
.modal-to-row label { font-size: 13px; font-weight: 600; white-space: nowrap; }
.modal-to-row input {
  flex: 1; padding: .4rem .65rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
}
.modal-to-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,174,239,.15); }

/* ─── Dark mode ─────────────────────────────── */
[data-theme="dark"] {
  --bg:      #0f1117;
  --surface: #1a1d23;
  --border:  #2d3340;
  --text:    #dde3ef;
  --muted:   #8892a4;
  --shadow:  0 2px 8px rgba(0,0,0,.5), 0 6px 24px rgba(0,0,0,.4);
  --nav-bg:  var(--nav-bg, #16191f);
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] nav {
  background: #16191f;
  border-bottom-color: var(--accent, #00AEEF);
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
[data-theme="dark"] .nav-links a { color: var(--muted); }
[data-theme="dark"] .nav-links a:hover { color: #fff; background: rgba(255,255,255,.08); }
[data-theme="dark"] .nav-user { background: rgba(0,174,239,.15); color: var(--accent, #00AEEF); border-color: rgba(0,174,239,.3); }
[data-theme="dark"] .table-wrap,
[data-theme="dark"] .form-wrap,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .filter-bar,
[data-theme="dark"] .auth-card,
[data-theme="dark"] .modal-box { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] thead tr { background: #22262e; }
[data-theme="dark"] th { color: var(--muted); border-color: var(--border); }
[data-theme="dark"] td { border-color: var(--border); }
[data-theme="dark"] tr:hover td { background: rgba(255,255,255,.03); }
[data-theme="dark"] tr.overdue td { background: rgba(180,83,9,.15) !important; }
[data-theme="dark"] code { background: #22262e; color: var(--text); }
[data-theme="dark"] .tab { background: transparent; border-color: var(--border); color: var(--muted); }
[data-theme="dark"] .tab.active { background: var(--brand, #002B7F); border-color: var(--brand, #002B7F); color: #fff; }
[data-theme="dark"] .field input,
[data-theme="dark"] .field textarea,
[data-theme="dark"] .field select,
[data-theme="dark"] .inline-edit,
[data-theme="dark"] .status-select,
[data-theme="dark"] .filter-select,
[data-theme="dark"] .filter-search,
[data-theme="dark"] .work-item-row input { background: #22262e; color: var(--text); border-color: var(--border); }
[data-theme="dark"] .btn-secondary { color: var(--muted); border-color: var(--border); background: transparent; }
[data-theme="dark"] .btn-secondary:hover { background: rgba(255,255,255,.06); }
[data-theme="dark"] .alert-success { background: #052e16; }
[data-theme="dark"] .alert-warning { background: #1c1400; }
[data-theme="dark"] .alert-error   { background: #1f0a0a; }
[data-theme="dark"] .badge-admin    { background: #1e2a4a; color: #7aa2f7; }
[data-theme="dark"] .badge-engineer { background: #0a2e1a; color: #73d399; }
[data-theme="dark"] .client-badge   { background: #0a1f2e; color: #38bdf8; }
