:root {
    --wine: #6b0d2c;
    --wine-dark: #4a071e;
    --wine-deep: #360515;
    --cream: #f7f0e9;
    --cream-2: #efe3d6;
    --sand: #e3cdb6;
    --gold: #c9a27e;
    --ink: #2b1a1f;
    --muted: #806a6e;
    --line: #eadfd5;
    --bg: #f8f4f0;
    --ok: #1f8a4c;
    --danger: #b3261e;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Tajawal', system-ui, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.6; }
a { color: var(--wine); text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
code { background: var(--cream-2); padding: 1px 6px; border-radius: 6px; direction: ltr; display: inline-block; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: .65em 1.4em; border-radius: 12px; border: 1.5px solid var(--wine);
    background: var(--wine); color: #fff; font: inherit; font-weight: 700; cursor: pointer;
    transition: background .2s, transform .15s;
}
.btn:hover { background: var(--wine-dark); }
.btn:active { transform: scale(.98); }
.btn-ghost { background: transparent; color: var(--wine); }
.btn-ghost:hover { background: var(--cream); }
.btn-danger { background: transparent; color: var(--danger); border-color: #e9c3c0; }
.btn-danger:hover { background: #fbeceb; }
.btn-link { background: none; border-color: transparent; color: var(--muted); }
.btn-link:hover { background: none; color: var(--wine); }
.btn-sm { padding: .35em .9em; font-size: .88rem; border-radius: 9px; }
.btn-block { width: 100%; padding: .85em; }

/* Forms */
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .95rem; margin-bottom: 16px; }
.form input:not([type=checkbox]):not([type=file]), .form select, .form textarea, .toolbar input, .toolbar select {
    font: inherit; font-weight: 400; padding: .7em .9em; border: 1.5px solid var(--line); border-radius: 12px;
    background: #fff; color: var(--ink); width: 100%; transition: border-color .2s, box-shadow .2s;
}
.form input:focus, .form select:focus, .form textarea:focus, .toolbar input:focus {
    outline: none; border-color: var(--wine); box-shadow: 0 0 0 3px rgba(107,13,44,.1);
}
.form textarea { resize: vertical; }
.hint { color: var(--muted); font-weight: 400; font-size: .82rem; }
.req { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 12px; }
.span-2 { grid-column: span 2; }
fieldset { border: 1.5px solid var(--line); border-radius: 16px; padding: 18px 18px 4px; margin: 0 0 18px; }
legend { font-weight: 700; color: var(--wine); padding: 0 8px; }
details { margin-bottom: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-bottom: 12px; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; margin-top: 10px; font-weight: 400 !important; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }

.switches { display: flex; gap: 26px; flex-wrap: wrap; }
.switch { flex-direction: row !important; align-items: center; gap: 10px !important; cursor: pointer; margin-bottom: 4px !important; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 44px; height: 24px; border-radius: 99px; background: #d9cdc3; position: relative; transition: .2s; flex: none; }
.switch span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--wine); }
.switch input:checked + span::after { right: 23px; }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(107,13,44,.25); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 500; }
.alert-error { background: #fbeceb; color: var(--danger); border: 1px solid #f0cfcc; }
.alert-success { background: #e8f5ed; color: var(--ok); border: 1px solid #c6e6d2; }

/* Auth / installer */
.auth-page {
    min-height: 100vh; display: grid; place-items: center; padding: 30px 16px;
    background: radial-gradient(circle at 20% 10%, #8b1d40, transparent 50%), linear-gradient(135deg, var(--wine-deep), var(--wine));
}
.auth-card { width: min(420px, 100%); background: #fff; border-radius: 26px; padding: 0 30px 30px; box-shadow: 0 30px 70px -20px rgba(0,0,0,.5); overflow: hidden; }
.install-card { width: min(620px, 100%); }
.auth-brand { background: linear-gradient(135deg, var(--wine-dark), var(--wine)); margin: 0 -30px 26px; padding: 26px; display: flex; justify-content: center; }
.auth-brand img { height: 84px; }
.auth-card h1 { color: var(--wine); font-size: 1.6rem; margin-bottom: 4px; }
.auth-card > .muted { margin: 0 0 20px; }
.back-link { display: block; text-align: center; margin-top: 16px; color: var(--muted); font-size: .9rem; }
.actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.checks { list-style: none; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: .9rem; }
.checks li { display: flex; gap: 8px; align-items: center; }
.checks li span { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; color: #fff; flex: none; }
.checks .ok span { background: var(--ok); }
.checks .bad { color: var(--danger); }
.checks .bad span { background: var(--danger); }
.success-mark { width: 74px; height: 74px; border-radius: 50%; background: #e8f5ed; color: var(--ok); display: grid; place-items: center; margin-bottom: 14px; }
.success-mark svg { width: 40px; height: 40px; }

/* Admin layout */
.admin { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex: none; background: linear-gradient(180deg, var(--wine-dark), var(--wine-deep));
    color: #fff; display: flex; flex-direction: column; padding: 22px 14px; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; justify-content: center; padding: 6px 0 26px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 16px; }
.side-brand img { height: 66px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar a, .sidebar button {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
    color: rgba(255,255,255,.78); font: inherit; font-weight: 500; background: none; border: 0; width: 100%; cursor: pointer; text-align: start;
}
.sidebar a:hover, .sidebar button:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar a.active { background: var(--cream); color: var(--wine); font-weight: 700; }
.sidebar svg { width: 20px; height: 20px; flex: none; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding-top: 12px; }
.side-foot form { margin: 0; }

.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 20px 32px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 1.35rem; color: var(--wine); }
.who { margin-inline-start: auto; color: var(--muted); font-size: .9rem; }
.side-toggle { display: none; background: none; border: 0; font-size: 1.5rem; color: var(--wine); cursor: pointer; }
.content { padding: 28px 32px 60px; max-width: 1150px; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 22px; margin-bottom: 20px; }
.card-title { font-size: 1.08rem; color: var(--wine); margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar { display: flex; gap: 8px; flex: 1; max-width: 620px; }
.toolbar input { flex: 2; }
.toolbar select { flex: 1; width: auto; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; gap: 14px; align-items: center; }
.stat > span { width: 48px; height: 48px; border-radius: 14px; background: var(--cream); color: var(--wine); display: grid; place-items: center; flex: none; }
.stat svg { width: 24px; height: 24px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1; color: var(--ink); }
.stat small { color: var(--muted); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: .85rem; color: var(--muted); font-weight: 500; padding: 10px; border-bottom: 1.5px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-off td:not(:nth-child(4)) { opacity: .5; }
.table form { margin: 0; }
.thumb { width: 60px; height: 60px; border-radius: 12px; overflow: hidden; background: var(--cream); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.title-link { font-weight: 700; color: var(--ink); }
.title-link:hover { color: var(--wine); }
.sub { color: var(--muted); font-size: .85rem; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.pill { display: inline-block; font: inherit; font-size: .8rem; padding: 2px 10px; border-radius: 99px; background: var(--cream); color: var(--wine); border: 0; white-space: nowrap; }
button.pill { cursor: pointer; }
.pill-on { background: #e8f5ed; color: var(--ok); }
.pill-off { background: #f1ebe6; color: var(--muted); }
.pill-gold { background: #f6ead9; color: #8a5a1e; margin-inline-start: 6px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

.product-form { display: grid; grid-template-columns: 1.4fr 1fr; gap: 0 20px; align-items: start; }
.product-form .form-actions { grid-column: 1 / -1; }
.dropzone {
    position: relative; border: 2px dashed var(--sand); border-radius: 16px; min-height: 260px;
    display: grid !important; place-items: center; cursor: pointer; overflow: hidden; background: var(--cream); margin: 0 !important;
    transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--wine); background: #f3e8de; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone img { width: 100%; height: 100%; max-height: 380px; object-fit: contain; }
.dz-text { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); text-align: center; padding: 20px; pointer-events: none; }
.dz-text svg { width: 44px; height: 44px; color: var(--wine); opacity: .6; }
.dz-text b { color: var(--wine); }
.dropzone [hidden] { display: none !important; }

.cat-row { display: flex; gap: 8px; align-items: center; flex: 1; margin: 0; }
.cat-row input:not(.num), .cat-row select { flex: 1; }
.cat-row .num { width: 80px !important; flex: none; }
.cat-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cat-item:last-child { border-bottom: 0; }
.cat-ico { width: 42px; height: 42px; border-radius: 50%; background: var(--wine); color: var(--cream); display: grid; place-items: center; flex: none; }
.cat-ico svg { width: 22px; height: 22px; }

@media (max-width: 1000px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .product-form { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; inset: 0 0 0 auto; z-index: 30; transform: translateX(100%); transition: transform .3s; box-shadow: -10px 0 40px rgba(0,0,0,.3); }
    .sidebar.open { transform: none; }
    .side-toggle { display: block; }
    .topbar { padding: 14px 16px; }
    .content { padding: 18px 16px 50px; }
    .cat-row { flex-wrap: wrap; }
    .cat-row input:not(.num), .cat-row select { flex: 1 1 45%; }
    .cat-item { align-items: flex-start; }
    .cat-item .pill { display: none; }
}
@media (max-width: 560px) {
    .grid-2, .grid-3, .checks { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .toolbar { flex-wrap: wrap; max-width: none; }
    .toolbar input { flex: 1 1 100%; }
    .who { display: none; }
    .table thead { display: none; }
    .table tr { display: grid; grid-template-columns: 64px 1fr; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
    .table td { border: 0; padding: 0; }
    .table td:first-child { grid-row: span 4; }
    .table td:nth-child(5) { display: none; }
    .row-actions { justify-content: flex-start; }
}
