:root {
    --bg: #f4f7fb;
    --bg-accent: #e8eef7;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #475569;
    --border: #e2e8f0;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 20px rgba(15, 23, 42, 0.06);
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.09);
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --danger-text: #991b1b;
    --radius: 14px;

    /*
     * Arabic-first UI: Tajawal + Cairo. Latin / English inherits Noto Sans in reading order via body rule.
     */
    --font-ar: "Tajawal", "Cairo", system-ui, sans-serif;
    --font-en: "Noto Sans", system-ui, sans-serif;
}

html {
    font-size: 16px;
}

/* Arabic interfaces */
html[lang="ar"],
html[lang="ar"] body {
    font-family: var(--font-ar), var(--font-en);
}

html[lang="en"] body {
    font-family: var(--font-en), var(--font-ar);
}

body.admin-ui {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(37, 99, 235, 0.08), transparent 55%),
        radial-gradient(900px 400px at 100% 0%, rgba(14, 165, 233, 0.07), transparent 45%),
        var(--bg);
    color: var(--text);
    line-height: 1.55;
}

.admin-shell {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
}

.admin-header {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.admin-header a {
    color: inherit;
    text-decoration: none;
}

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.admin-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 18px 48px;
}

.card {
    max-width: 440px;
    width: 100%;
    padding: 24px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.admin-shell > .card {
    margin-block: clamp(48px, 10vh, 120px);
    margin-inline: auto;
}

.card h1 {
    margin: 0 0 8px;
    font-size: 1.35rem;
    font-weight: 700;
}

label {
    display: block;
    margin: 12px 0 6px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

input[type="password"],
input[type="text"],
button,
.btn {
    font: inherit;
}

input[type="password"],
input[type="text"],
textarea.admin-json {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

textarea.admin-json {
    min-height: 58vh;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Noto Sans Mono", monospace;
    font-size: 13px;
    line-height: 1.5;
}

input[type="password"]:focus,
input[type="text"]:focus,
textarea.admin-json:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.45);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    cursor: pointer;
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.btn.btn-primary,
.admin-login-card button[type="submit"] {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #fff;
}

.admin-login-card button[type="submit"] {
    margin-top: 14px;
    width: 100%;
}

.invoice-save-actions .btn.btn-primary {
    margin-top: 14px;
}

.btn:hover {
    background: rgba(37, 99, 235, 0.14);
    border-color: rgba(37, 99, 235, 0.18);
}

.admin-login-card button[type="submit"]:hover,
button[type="submit"].btn-primary:hover,
.btn.btn-primary:hover {
    background: linear-gradient(180deg, var(--accent-hover) 0%, var(--accent) 100%);
    border-color: transparent;
    filter: brightness(1.02);
}

.btn.small {
    padding: 8px 10px;
    font-size: 0.85rem;
    margin-top: 0;
    width: auto;
}

.err {
    margin: 14px 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
    font-weight: 600;
}

.hint {
    margin-top: 14px;
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.65;
}

.hint code {
    font-family: ui-monospace, monospace;
    font-size: 0.8em;
}

table.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

table.admin-table thead th {
    background: var(--bg-accent);
}

table.admin-table th,
table.admin-table td {
    padding: 12px 11px;
    border-bottom: 1px solid var(--border);
    text-align: inherit;
    vertical-align: top;
}

table.admin-table th {
    font-weight: 700;
    color: var(--text-muted);
}

table.admin-table tbody tr:last-child td {
    border-bottom: none;
}

code.admin-inline-code {
    background: var(--bg-accent);
    border: 1px solid var(--border);
    padding: 3px 6px;
    border-radius: 8px;
    font-size: 0.88em;
}

td .btn {
    margin-inline-end: 6px;
    margin-block: 4px;
}

.muted {
    color: var(--text-muted);
    margin-top: 10px;
    font-size: 0.875rem;
    line-height: 1.65;
}

/* --- Invoice form editor --- */

.form-card {
    margin-bottom: 20px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.form-card legend {
    font-weight: 800;
    font-size: 1.05rem;
    padding-inline: 6px;
    color: var(--text);
}

.form-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 720px) {
    .form-two {
        grid-template-columns: 1fr;
    }
}

.repeat-block {
    margin-top: 8px;
}

.repeat-row-simple {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.repeat-row-simple .grow {
    flex: 1 1 auto;
}

.repeat-meta-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

.repeat-meta-row .meta-actions {
    display: flex;
    justify-content: flex-start;
}

@media (max-width: 900px) {
    .repeat-meta-row {
        grid-template-columns: 1fr 1fr;
    }

    .repeat-meta-row .meta-actions {
        grid-column: 1 / -1;
    }
}

.line-items-head {
    display: grid;
    grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr));
    gap: 8px;
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-inline: 2px;
}

.repeat-line-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)) auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

@media (max-width: 980px) {
    .repeat-line-row,
    .line-items-head {
        grid-template-columns: 1fr 1fr;
    }

    .repeat-line-row .line-actions {
        grid-column: 1 / -1;
    }

    .line-items-head span:nth-child(n + 3) {
        display: none;
    }
}

.invoice-save-bar {
    margin-top: 10px;
    padding-top: 18px;
    border-top: 1px dashed var(--border);
}

textarea.form-textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 100px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    line-height: 1.55;
    resize: vertical;
}

textarea.form-textarea:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.45);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.btn-row {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

input[type="text"].field-text {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

input[type="text"].field-text:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.45);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
