/* ════════════════════════════════════════════════════════════════
   Pearl Isle ERP — Main Stylesheet
   Brand: Purple #5B2D8E  Green #6B8E2A
   ════════════════════════════════════════════════════════════════ */

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

:root {
  --purple:      #5B2D8E;
  --purple-dark: #461f72;
  --purple-light:#7B4DB3;
  --green:       #6B8E2A;
  --green-light: #8BB33A;
  --white:       #ffffff;
  --bg:          #F4F2F8;
  --surface:     #ffffff;
  --border:      #E2DCF0;
  --text:        #1a1a2e;
  --text-muted:  #6b6b8a;
  --danger:      #C0392B;
  --warning:     #E67E22;
  --success:     #27AE60;
  --info:        #2980B9;

  --sidebar-w:   240px;
  --topbar-h:    60px;
  --radius:      8px;
  --radius-sm:   4px;
  --shadow:      0 2px 8px rgba(91,45,142,.10);
  --shadow-md:   0 4px 16px rgba(91,45,142,.14);

  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Consolas', monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
a { color: var(--purple); text-decoration: none; }
a:hover { color: var(--purple-dark); text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ── Top bar ──────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--white);
  color: var(--purple-dark);
  border-bottom: 3px solid var(--purple);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(91,45,142,.12);
}

.topbar-left { display: flex; align-items: center; gap: .8rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }

.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; gap: 5px; padding: 4px;
}
.sidebar-toggle span {
  display: block; width: 22px; height: 2px;
  background: var(--purple);
  border-radius: 2px;
  transition: transform .2s;
}

.brand {
  display: flex; align-items: center; gap: .6rem;
  color: var(--purple-dark); text-decoration: none;
}
.brand-logo { height: 44px; width: auto; }
.brand-name {
  font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em;
  color: var(--purple-dark);
}
.brand-name em { font-style: normal; color: var(--green); }

.user-pill {
  display: flex; align-items: center; gap: .4rem;
  font-size: .85rem; color: var(--text-muted);
}
.user-pill svg { width: 18px; height: 18px; stroke: var(--purple); }
.role-tag {
  background: var(--purple);
  color: #fff;
  border-radius: 20px;
  padding: 1px 8px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.btn-logout {
  color: var(--purple);
  font-size: .82rem;
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  text-decoration: none;
  transition: background .15s;
}
.btn-logout:hover { background: #F0EBF8; text-decoration: none; color: var(--purple-dark); }

/* ── Layout ───────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--topbar-h);
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  transition: transform .25s ease;
  z-index: 100;
}

.sidebar-inner { padding: 1rem 0; }

.nav-section-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 1rem 1.2rem .3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem 1.2rem;
  color: var(--text);
  font-size: .9rem;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
}
.nav-link:hover {
  background: #F0EBF8;
  color: var(--purple);
  text-decoration: none;
}
.nav-link.active {
  background: #F0EBF8;
  border-left-color: var(--purple);
  color: var(--purple);
  font-weight: 600;
}
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-icon svg { width: 100%; height: 100%; }

/* ── Main content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1.75rem;
  min-width: 0;
}

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--purple-dark);
}
.breadcrumb {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .3rem;
}
.breadcrumb a { color: var(--purple); }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--purple-dark);
}

/* ── Dashboard stat cards ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--purple);
}
.stat-card.green { border-top-color: var(--green); }
.stat-card.warn  { border-top-color: var(--warning); }
.stat-card.info  { border-top-color: var(--info); }

.stat-icon {
  background: #F0EBF8;
  border-radius: var(--radius-sm);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card.green .stat-icon { background: #EDF4E0; }
.stat-card.warn  .stat-icon { background: #FEF3E2; }
.stat-card.info  .stat-icon { background: #E8F4FB; }
.stat-icon svg { width: 22px; height: 22px; stroke: var(--purple); }
.stat-card.green .stat-icon svg { stroke: var(--green); }
.stat-card.warn  .stat-icon svg { stroke: var(--warning); }
.stat-card.info  .stat-icon svg { stroke: var(--info); }

.stat-body { flex: 1; min-width: 0; }
.stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}
.stat-label {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
thead th {
  background: #F5F0FB;
  color: var(--purple-dark);
  font-weight: 600;
  padding: .65rem .9rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #FAF8FE; }
td { padding: .6rem .9rem; vertical-align: middle; }
.td-mono { font-family: var(--font-mono); font-size: .83rem; }
.td-right { text-align: right; }
.td-center { text-align: center; }

/* ── Badges / Status ──────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-draft      { background: #EDE9F5; color: #5B2D8E; }
.badge-approved   { background: #EDF4E0; color: #3D6010; }
.badge-sent       { background: #E8F4FB; color: #1A5E8A; }
.badge-received   { background: #E0F5ED; color: #1A7A4A; }
.badge-cancelled  { background: #FBEAEA; color: #8B2020; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .48rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--purple);
  color: var(--white);
}
.btn-primary:hover { background: var(--purple-dark); color: var(--white); text-decoration: none; }
.btn-success {
  background: var(--green);
  color: var(--white);
}
.btn-success:hover { background: #57731e; color: var(--white); text-decoration: none; }
.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); text-decoration: none; }
.btn-danger {
  background: var(--danger);
  color: var(--white);
}
.btn-danger:hover { background: #96301f; color: var(--white); text-decoration: none; }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }
.btn-link {
  background: none; border: none; padding: 0;
  color: var(--purple); cursor: pointer;
  font-size: inherit; font-family: inherit;
}
.btn-link:hover { text-decoration: underline; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label {
  display: block;
  font-size: .83rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .3rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  width: 100%;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--purple-light);
  box-shadow: 0 0 0 3px rgba(91,45,142,.12);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: .25rem; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
  padding: .85rem 1.1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .9rem;
  border-left: 4px solid;
}
.alert-success { background: #EDF4E0; border-color: var(--success); color: #2a6030; }
.alert-error, .alert-danger { background: #FBEAEA; border-color: var(--danger); color: #7c2020; }
.alert-warning { background: #FEF3E2; border-color: var(--warning); color: #7a4a0a; }
.alert-info    { background: #E8F4FB; border-color: var(--info);    color: #1a4a6e; }

/* ── Search / Filter bar ──────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filter-bar .form-control { max-width: 200px; }
.filter-bar input[type="search"] { max-width: 260px; }

/* ── PO items table (inside form) ─────────────────────────────── */
.items-table thead th { font-size: .75rem; }
.items-table input { padding: .35rem .5rem; font-size: .85rem; }
.items-table td { padding: .4rem .5rem; }
.line-total { font-family: var(--font-mono); font-size: .83rem; }
.btn-remove-row {
  background: none; border: none; cursor: pointer;
  color: var(--danger); font-size: 1.1rem; line-height: 1;
  padding: 2px 6px;
}
.btn-remove-row:hover { color: #7c2020; }

/* ── Totals row ───────────────────────────────────────────────── */
.totals-box {
  margin-top: .75rem;
  display: flex;
  justify-content: flex-end;
}
.totals-inner {
  min-width: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: .45rem .85rem;
  font-size: .88rem;
  border-bottom: 1px solid var(--border);
}
.totals-row:last-child {
  border-bottom: none;
  font-weight: 700;
  background: #F5F0FB;
  font-size: .95rem;
}

/* ── Document list ────────────────────────────────────────────── */
.doc-list { list-style: none; }
.doc-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
  font-size: .88rem;
  background: var(--surface);
}
.doc-list li svg { width: 18px; height: 18px; stroke: var(--danger); flex-shrink: 0; }
.doc-meta { color: var(--text-muted); font-size: .75rem; margin-left: .4rem; }

/* ── Status log ───────────────────────────────────────────────── */
.status-log { list-style: none; position: relative; }
.status-log::before {
  content: ''; position: absolute; left: 9px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.status-log li {
  display: flex; gap: .75rem;
  padding-left: 28px; position: relative;
  margin-bottom: .75rem; font-size: .85rem;
}
.status-log li::before {
  content: ''; position: absolute; left: 4px; top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--purple); border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--purple);
}
.status-log .log-time { color: var(--text-muted); font-size: .75rem; white-space: nowrap; }

/* ── Pagination ───────────────────────────────────────────────── */
.pagination {
  display: flex; gap: .4rem; justify-content: center;
  margin-top: 1.25rem; flex-wrap: wrap;
}
.page-link {
  display: inline-block; padding: .35rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .82rem; color: var(--text);
  text-decoration: none; transition: background .15s;
}
.page-link:hover { background: #F0EBF8; text-decoration: none; }
.page-link.active { background: var(--purple); color: var(--white); border-color: var(--purple); }

/* ── Upload zone ──────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--purple-light); background: #FAF8FE; }
.upload-zone svg { width: 40px; height: 40px; stroke: var(--text-muted); margin-bottom: .5rem; }
.upload-zone p { font-size: .88rem; color: var(--text-muted); }
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── Login page ───────────────────────────────────────────────── */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple) 60%, #7B4DB3 100%);
}
.login-box {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-logo img { height: 60px; width: auto; }
.login-logo h1 { font-size: 1.3rem; font-weight: 700; color: var(--purple-dark); margin-top: .5rem; }
.login-logo p  { font-size: .82rem; color: var(--text-muted); }
.login-box .btn-primary { width: 100%; justify-content: center; padding: .7rem; font-size: 1rem; }

/* ── Footer ───────────────────────────────────────────────────── */
.site-footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: .6rem 1.75rem;
  font-size: .75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ── Utility ──────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.gap-1 { gap: .5rem; }
.flex { display: flex; align-items: center; }
.d-none { display: none; }
.w-100 { width: 100%; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h); left: 0;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%);
    z-index: 150;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
