:root {
  --blue: #0f4c97;
  --blue-dark: #0a3a78;
  --blue-50: #eef4fc;
  --blue-100: #dbe8fa;
  --ink: #1b2530;
  --muted: #647184;
  --line: #e8ecf2;
  --bg: #eef1f6;
  --ok: #0f9d58;
  --warn: #c77700;
  --bad: #d14343;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 56, 0.06), 0 1px 3px rgba(16, 32, 56, 0.05);
  --shadow: 0 6px 18px rgba(16, 32, 56, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 32, 56, 0.16);
}

* { box-sizing: border-box; }
.min-w-0 { min-width: 0; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ====================== LOGIN ====================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 255, 255, 0.18), transparent 60%),
    linear-gradient(135deg, #0f4c97 0%, #0a3a78 60%, #082d5e 100%);
}

.login-card {
  width: 100%;
  max-width: 410px;
  background: #fff;
  border-radius: 20px;
  padding: 2.4rem 2rem 1.6rem;
  box-shadow: var(--shadow-lg);
  animation: pop 0.4s ease;
}

.login-brand { text-align: center; margin-bottom: 0.6rem; }
.login-brand img { width: 72px; }
.login-card h1 { font-size: 1.45rem; font-weight: 800; text-align: center; color: var(--blue); margin: 0.2rem 0 0.4rem; }
.login-lead { font-size: 0.9rem; color: var(--muted); text-align: center; margin: 0 0 1.6rem; }
.login-card .form-control { border-radius: 10px; }
.login-card .form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 0.2rem rgba(15, 76, 151, 0.18); }
.login-pass-toggle {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  padding: 0.15rem 0.35rem;
  font-size: 1.1rem;
  line-height: 1;
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
}

.login-forgot { color: var(--blue); font-weight: 600; font-size: 0.86rem; text-decoration: none; }
.login-forgot:hover { color: var(--blue-dark); text-decoration: underline; }
.login-back { display: block; text-align: center; margin-top: 1.2rem; color: var(--muted); text-decoration: none; font-size: 0.86rem; }
.login-back:hover { color: var(--blue); }

.btn-brand {
  background: var(--blue);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  transition: background 0.2s ease, transform 0.1s ease;
}
.btn-brand:hover { background: var(--blue-dark); color: #fff; }
.btn-brand:active { transform: translateY(1px); }

.btn-outline-brand {
  background: #fff;
  border: 1px solid var(--blue);
  color: var(--blue);
  font-weight: 600;
  border-radius: 10px;
}
.btn-outline-brand:hover { background: var(--blue-50); color: var(--blue-dark); }

/* ====================== APP SHELL ====================== */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-navbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #fff;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--line);
}
.app-navbar__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.app-navbar__inner {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.app-brand__logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--blue-50);
  display: grid; place-items: center;
  color: var(--blue);
  font-size: 1.3rem;
  flex-shrink: 0;
  overflow: hidden;
}
.app-brand__logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.app-brand__txt { min-width: 0; }
.app-brand__txt strong { display: block; font-size: 0.98rem; color: var(--ink); line-height: 1.1; }
.app-brand__client { display: block; font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-ghost {
  background: var(--blue-50);
  border: none;
  color: var(--blue);
  font-weight: 600;
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  transition: background 0.2s ease;
}
.btn-ghost:hover { background: var(--blue-100); color: var(--blue-dark); }

/* Tabs */
.app-tabs-wrap {
  position: sticky;
  top: 61px;
  z-index: 25;
  background: var(--bg);
  padding-top: 0.6rem;
}
.app-tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-tabs::-webkit-scrollbar { display: none; }
.ptab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.6rem 1rem;
  border-radius: 12px 12px 0 0;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
}
.ptab:hover { color: var(--blue); background: rgba(255, 255, 255, 0.6); }
.ptab.is-active {
  color: var(--blue);
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.ptab.is-active::after {
  content: "";
  position: absolute;
  left: 1rem; right: 1rem; bottom: -1px;
  height: 3px;
  background: var(--blue);
  border-radius: 3px 3px 0 0;
}

/* Main */
.app-main { flex: 1; padding: 1.4rem 0 2rem; }
.app-container { max-width: 1400px; width: 92%; margin: 0 auto; }

.ppanel { display: none; animation: fadeUp 0.3s ease; }
.ppanel.is-active { display: block; }

.section-head { margin-bottom: 1rem; }
.section-head h2 { font-size: 1.3rem; font-weight: 800; color: var(--ink); margin: 0; }
.section-head p { color: var(--muted); margin: 0.2rem 0 0; font-size: 0.9rem; }
.section-head--actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.docs-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  font-size: 0.9rem;
}

.docs-banner__meta { color: var(--muted); }

.docs-banner--approve {
  background: #fffbeb;
  border-color: #fcd34d;
}

.docs-banner--approve .pill.amber {
  font-weight: 600;
}

.section-head--actions .btn-brand {
  padding: 0.55rem 1.1rem;
  white-space: nowrap;
}
.nt-modal { border: none; border-radius: 16px; overflow: hidden; }
.nt-modal .modal-header { background: var(--blue); color: #fff; border-bottom: none; }
.nt-modal .modal-header .btn-close { filter: invert(1) grayscale(1) brightness(2); }
.nt-modal .modal-title { font-weight: 800; }
.nt-modal .form-label { font-weight: 600; color: var(--ink); font-size: 0.9rem; }

/* ====================== KPI CARDS ====================== */
.kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-sm);
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi__icon {
  width: 50px; height: 50px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.kpi__icon.blue { background: var(--blue-50); color: var(--blue); }
.kpi__icon.green { background: #e4f6ec; color: var(--ok); }
.kpi__icon.amber { background: #fcf1dd; color: var(--warn); }
.kpi__icon.violet { background: #efeafd; color: #6d4ad1; }
.kpi__k { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; }
.kpi__v { font-size: 1.18rem; font-weight: 800; color: var(--ink); line-height: 1.2; margin-top: 2px; word-break: break-word; }

/* ====================== CARDS ====================== */
.pcard {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.pcard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 1.05rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.pcard__head h3 { font-size: 1.02rem; font-weight: 800; margin: 0; color: var(--ink); display: flex; align-items: center; gap: 0.5rem; }
.pcard__head .ico { color: var(--blue); }
.pcard__body { padding: 1.1rem 1.25rem; }

/* Contract detail */
.contract-num { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; margin-bottom: 1rem; }
.detail-item { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.7rem 0.85rem; }
.detail-item .lbl { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.detail-item .val { font-size: 0.98rem; font-weight: 700; color: var(--ink); margin-top: 2px; }
.sys-title { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; margin: 0.4rem 0 0.5rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: var(--blue-50);
  color: var(--blue);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Status badge */
.stbadge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.stbadge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.stbadge.green { background: #e4f6ec; color: var(--ok); }
.stbadge.amber { background: #fcf1dd; color: var(--warn); }
.stbadge.red { background: #fbe9e9; color: var(--bad); }
.stbadge.gray { background: #eef0f4; color: var(--muted); }

/* Side widgets */
.widget + .widget { margin-top: 1rem; }
.widget__row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--line);
}
.widget__row:last-child { border-bottom: none; }
.widget__ico {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; flex-shrink: 0;
  background: var(--blue-50); color: var(--blue); font-size: 0.95rem;
}
.widget__main { min-width: 0; flex: 1; }
.widget__t { font-size: 0.86rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget__s { font-size: 0.76rem; color: var(--muted); }
.widget__big { font-size: 1.6rem; font-weight: 800; color: var(--ink); }

.btn-download {
  background: var(--blue);
  border: none; color: #fff; font-weight: 700;
  border-radius: 12px;
  padding: 0.7rem 1.1rem;
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  transition: background 0.2s ease, transform 0.1s ease;
}
.btn-download:hover { background: var(--blue-dark); color: #fff; }
.btn-download:active { transform: translateY(1px); }

/* ====================== TABLES ====================== */
.ptable-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.ptable { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.ptable thead th {
  background: #f7f9fc;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.8rem 1rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.ptable tbody td { padding: 0.8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ptable tbody tr:last-child td { border-bottom: none; }
.ptable tbody tr { transition: background 0.15s ease; }
.ptable tbody tr:hover { background: #f8fbff; }
.cell-strong { font-weight: 700; color: var(--ink); }
.cell-muted { color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.22rem 0.65rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
}
.pill.green { background: #e4f6ec; color: var(--ok); }
.pill.blue { background: var(--blue-50); color: var(--blue); }
.pill.gray { background: #eef0f4; color: var(--muted); }
.pill.red { background: #fbe9e9; color: var(--bad); }

.btn-mini {
  background: var(--blue);
  border: none; color: #fff;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.35rem;
  transition: background 0.2s ease;
}
.btn-mini:hover { background: var(--blue-dark); color: #fff; }
.btn-mini:disabled { opacity: 0.6; }

/* ====================== TOOLBAR / PAGER ====================== */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.8rem; flex-wrap: wrap;
}
.searchbox { max-width: 380px; flex: 1 1 240px; }
.searchbox .input-group-text { background: #fff; border-right: none; color: var(--muted); }
.searchbox .form-control { border-left: none; }
.searchbox .form-control:focus { box-shadow: none; border-color: var(--line); }
.searchbox .btn-brand { border-radius: 0 8px 8px 0; }
.table-count { font-size: 0.82rem; color: var(--muted); font-weight: 600; }

.table-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-top: 0.8rem; flex-wrap: wrap;
}
.pager-btns { display: flex; align-items: center; gap: 0.5rem; }
.pager-info { font-size: 0.84rem; color: var(--muted); font-weight: 600; }
.btn-page {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--blue);
  display: grid; place-items: center; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-page:hover:not(:disabled) { background: var(--blue-50); border-color: var(--blue-100); }
.btn-page:disabled { opacity: 0.4; cursor: not-allowed; }

/* invoice summary stat boxes */
.stat-box {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 0.95rem 1.05rem;
  display: flex; align-items: center; gap: 0.85rem; height: 100%;
}
.stat-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; flex-shrink: 0; }
.stat-ico.blue { background: var(--blue-50); color: var(--blue); }
.stat-ico.green { background: #e4f6ec; color: var(--ok); }
.stat-ico.amber { background: #fcf1dd; color: var(--warn); }
.stat-k { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.stat-v { font-size: 1.2rem; font-weight: 800; color: var(--ink); }

/* ====================== EMPTY / SKELETON ====================== */
.empty-state {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 2.6rem 1.5rem;
  text-align: center;
  color: var(--muted);
}
.empty-state i { font-size: 2.4rem; color: var(--blue-100); display: block; margin-bottom: 0.6rem; }
.empty-state p { margin: 0; font-size: 0.92rem; }

.skel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.skel-line, .skel-box {
  background: linear-gradient(90deg, #eef1f6 25%, #e2e7ef 37%, #eef1f6 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: 8px;
}
.skel-line { height: 14px; margin-bottom: 0.6rem; }
.skel-line.w-60 { width: 60%; }
.skel-line.w-40 { width: 40%; }
.skel-line.w-80 { width: 80%; }
.skel-box { height: 60px; }

@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ====================== FOOTER ====================== */
.app-footer { background: #fff; border-top: 1px solid var(--line); margin-top: auto; }
.app-footer__inner {
  max-width: 1400px; margin: 0 auto;
  padding: 1rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem; flex-wrap: wrap;
}
.app-footer__sep { opacity: 0.5; }

/* ====================== ANIMATIONS ====================== */
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 575.98px) {
  .app-navbar__inner, .app-tabs, .app-footer__inner { padding-left: 1rem; padding-right: 1rem; }
  .app-container { width: 94%; }
  .detail-grid { grid-template-columns: 1fr; }
}

.sign-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  touch-action: none;
  background: #fff;
}
.btn-mini--ok {
  background: var(--ok);
  border-color: var(--ok);
}
.btn-mini--ok:hover {
  background: #0b7d45;
  border-color: #0b7d45;
}

.btn-mini--warn {
  background: #fff7ed;
  border-color: #fdba74;
  color: #9a3412;
}

.btn-mini--dl {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  color: var(--blue);
  font-weight: 600;
}
.btn-mini--dl:hover {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn-mini--info {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1d4ed8;
  font-weight: 600;
}
.btn-mini--info:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .kpi, .ptab, .btn-brand, .btn-download, .ppanel, .login-card { animation: none !important; transition: none !important; }
  .skel-line, .skel-box { animation: none; }
}
