/* ============================================================
   Aryu Shop - Management Portal styles
   ============================================================ */
:root {
  --brand: #6b2d5c;
  --brand-dark: #4f1f44;
  --brand-soft: #f4e9f1;
  --accent: #c8873a;
  --bg: #f6f4f1;
  --surface: #ffffff;
  --ink: #221b20;
  --muted: #6f6670;
  --line: #e6e0e3;
  --line-strong: #d2c9ce;
  --green: #2f7a4f;  --green-bg: #e5f3ea;
  --amber: #9a6410;  --amber-bg: #fbf0dc;
  --red: #b23a3a;    --red-bg: #fbe6e6;
  --blue: #2c5f94;   --blue-bg: #e4eef8;
  --grey: #6a6a6a;   --grey-bg: #efefef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(34, 27, 32, .05), 0 2px 8px rgba(34, 27, 32, .04);
  --sidebar: 240px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.text-red { color: var(--red); } .text-green { color: var(--green); } .text-amber { color: var(--amber); }

/* ---------- Layout ---------- */
.nav-toggle { display: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #2a1626; color: #e9dde5;
  overflow-y: auto; z-index: 30; padding-bottom: 2rem;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; font-weight: 700; color: #fff; }
.brand small { display: block; color: #b9a3b3; font-weight: 400; font-size: .75rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #2a1626;
  display: inline-grid; place-items: center; font-weight: 800; font-size: 1.1rem; flex: none;
}
.brand-mark.lg { width: 56px; height: 56px; font-size: 1.8rem; border-radius: 14px; }
.sidebar nav { padding: 0 .6rem; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #a58f9f; padding: 1rem .6rem .35rem; }
.sidebar nav a { display: block; color: #e9dde5; padding: .48rem .7rem; border-radius: 7px; font-size: .92rem; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 1.2rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; color: var(--ink); font-size: .88rem; }
.user-chip:hover { text-decoration: none; }
.user-chip small { display: block; font-size: .72rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.hamburger { display: none; cursor: pointer; width: 36px; height: 36px; padding: 9px 7px; border-radius: 8px; }
.hamburger span { display: block; height: 2px; background: var(--ink); margin-bottom: 5px; border-radius: 2px; }
.nav-overlay { display: none; }
.content { padding: 1.4rem 1.5rem 2rem; flex: 1; width: 100%; max-width: 1400px; }
.footer { padding: 1rem 1.5rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-bottom: 1rem; }

/* ---------- Cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1.2rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .7rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.2rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.55rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.stat.accent { border-left: 4px solid var(--brand); }
.stat.warn { border-left: 4px solid var(--amber); }
.stat.danger { border-left: 4px solid var(--red); }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #faf8f9; }
tbody tr:hover { background: #fcfafb; }
tfoot td { font-weight: 700; background: #faf8f9; }
td.empty { text-align: center; color: var(--muted); padding: 1.6rem; }
td.actions { white-space: nowrap; text-align: right; }
tr.row-cancelled td { color: var(--muted); text-decoration: line-through; }
tr.row-cancelled td.actions, tr.row-cancelled td .badge { text-decoration: none; }

/* ---------- Badges & alerts ---------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .5rem; border-radius: 99px; white-space: nowrap; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-grey { background: var(--grey-bg); color: var(--grey); }
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--green-bg); color: var(--green); border-color: #c6e4d0; }
.alert-error { background: var(--red-bg); color: var(--red); border-color: #f0c8c8; }
.alert-info { background: var(--blue-bg); color: var(--blue); border-color: #c8dbef; }
.alert-warn { background: var(--amber-bg); color: var(--amber); border-color: #f0dbb2; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .84rem; font-weight: 600; color: #4a4048; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid var(--line-strong);
  border-radius: 7px; padding: .5rem .6rem; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(107, 45, 92, .25); border-color: var(--brand); }
input[readonly] { background: #f7f5f6; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem 1rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.filters label { min-width: 140px; }
.filters label.grow { flex: 1; min-width: 180px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Line-item editor */
.lines td { padding: .35rem .3rem; vertical-align: middle; }
.lines input, .lines select { padding: .4rem .45rem; }
.lines .w-qty { width: 90px; } .lines .w-money { width: 110px; } .lines .w-tax { width: 80px; }
.lines .w-prod { min-width: 240px; }
.totals { margin-left: auto; max-width: 360px; }
.totals table td { border: none; padding: .3rem .4rem; }
.totals .grand td { font-size: 1.15rem; font-weight: 800; border-top: 2px solid var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .88rem;
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: #f7f3f5; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--brand-soft); border-color: #e3cfdd; color: var(--brand); }
.btn-danger { background: #fff; border-color: #e7b9b9; color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.inline-form { display: inline; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; font-size: .85rem; color: var(--muted); }
.progress { height: 8px; background: var(--grey-bg); border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress span { display: block; height: 100%; background: var(--brand); }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: .5rem; }
.bar-chart .bar { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bar-chart .bar:hover { opacity: 1; }
.bar-labels { display: flex; gap: 4px; font-size: .68rem; color: var(--muted); }
.bar-labels span { flex: 1; text-align: center; overflow: hidden; }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: #2a1626; padding: 16px; }
.login-wrap { display: grid; grid-template-columns: 1fr 1fr; max-width: 820px; width: 100%; background: var(--surface); border-radius: 16px; overflow: hidden; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.login-side { background: linear-gradient(160deg, var(--brand), #3a1733); color: #fff; padding: 2.5rem 2rem; display: flex; flex-direction: column; justify-content: flex-end; gap: .4rem; }
.login-side h1 { margin-top: 1rem; font-size: 1.8rem; }
.login-side p { color: #e8d6e2; margin: 0; }
.login-card { padding: 2.5rem 2rem; display: flex; flex-direction: column; gap: 1rem; }
.error-page { max-width: 520px; margin: 10vh auto; background: #fff; padding: 2rem; border-radius: 12px; border: 1px solid var(--line); }

/* ---------- Invoice / print ---------- */
.invoice { background: #fff; max-width: 900px; margin: 0 auto; padding: 2rem; border: 1px solid var(--line); border-radius: var(--radius); }
.invoice-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: 1rem; margin-bottom: 1rem; }
.invoice-head h2 { font-size: 1.5rem; margin: 0; }
.invoice .meta { text-align: right; }
.invoice-foot { margin-top: 1.5rem; text-align: center; color: var(--muted); font-size: .85rem; }

@media print {
  .sidebar, .topbar, .page-actions, .footer, .no-print, .filters, .nav-overlay, .pager { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; font-size: 12px; }
  .card, .invoice, .stat { box-shadow: none; border: none; padding: 0; }
  a { color: inherit; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 20px rgba(0, 0, 0, .3); }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .nav-toggle:checked ~ .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .user-meta { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-side { padding: 1.5rem; }
}
@media (max-width: 560px) {
  .content { padding: 1rem 16px 1.5rem; }
  .topbar { padding: .6rem 16px; }
  .topbar h1 { font-size: 1.05rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 1.2rem; }
  .invoice { padding: 1rem; }
  .filters label { min-width: 0; flex: 1 1 45%; }
}
