/* ========================================================
   ZATCA E-Invoicing System — Stylesheet
   Arabic-first RTL, modern minimal design
   ======================================================== */

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0;
    font-family: 'Segoe UI', 'Cairo', 'Tahoma', sans-serif;
    background: #f5f7fb;
    color: #222;
    line-height: 1.5;
    direction: rtl;
}

a { color: #1f4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
    background: #0f172a;
    color: #fff;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 600; }
.brand .logo { font-size: 1.5rem; }
.topnav { display: flex; gap: 18px; align-items: center; }
.topnav a { color: #fff; opacity: .85; }
.topnav a:hover { opacity: 1; text-decoration: none; }
.topnav .welcome { opacity: .7; font-size: .9rem; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 56px - 40px); }
.sidebar {
    width: 240px;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    padding: 16px 0;
    display: flex; flex-direction: column;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; flex: 1; }
.sidebar li a {
    display: block;
    padding: 10px 20px;
    color: #1f2937;
    border-right: 3px solid transparent;
}
.sidebar li a:hover { background: #f3f4f6; border-right-color: #1f4ed8; text-decoration: none; }
.env-badge { margin: 16px 20px; padding: 6px 12px; border-radius: 6px; text-align: center; font-size: .85rem; }
.env-sandbox { background: #fef3c7; color: #92400e; }
.env-simulation { background: #ddd6fe; color: #5b21b6; }
.env-production { background: #d1fae5; color: #065f46; }

.content { flex: 1; padding: 24px 32px; max-width: 1200px; }
.footer { background: #fff; padding: 10px 24px; text-align: center; color: #6b7280; border-top: 1px solid #e5e7eb; }

/* ---------- Headings ---------- */
h1, h2, h3 { color: #111827; }
h1 { font-size: 1.5rem; margin: 0 0 18px 0; }
h2 { font-size: 1.2rem; margin: 22px 0 12px 0; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.page-header .btn { white-space: nowrap; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #111827;
    border-radius: 6px;
    cursor: pointer;
    font-size: .95rem;
    text-decoration: none;
    transition: all .12s;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: #1f4ed8; color: #fff; border-color: #1f4ed8; }
.btn-primary:hover { background: #1e40af; }
.btn-block { display: block; width: 100%; text-align: center; }
.link-danger { background: transparent; border: 0; color: #dc2626; cursor: pointer; padding: 0 6px; }
.inline { display: inline-block; }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #10b981; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #ef4444; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }

/* ---------- Forms ---------- */
.form, form { background: #fff; padding: 18px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.04); margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label, .form label { display: block; font-size: .9rem; color: #374151; margin-bottom: 4px; }
.field input, .field select, .field textarea,
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: .95rem;
    font-family: inherit;
    background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #1f4ed8; outline-offset: -1px; }
textarea { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
fieldset { border: 1px solid #e5e7eb; border-radius: 6px; padding: 14px; margin: 14px 0; }
fieldset legend { padding: 0 8px; font-weight: 600; color: #374151; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.checkbox input { width: auto; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.04); border-radius: 8px; overflow: hidden; margin-bottom: 18px; }
.table th, .table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #f3f4f6; font-size: .92rem; }
.table thead { background: #f9fafb; }
.table th { font-weight: 600; color: #374151; }
.table tbody tr:hover { background: #fafbfc; }
.table .center { text-align: center; }
.table .actions { white-space: nowrap; display: flex; gap: 10px; align-items: center; }
.line-items th, .line-items td { padding: 6px 8px; }
.line-items input, .line-items select { padding: 5px 6px; font-size: .85rem; }

/* ---------- Status badges ---------- */
.status { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .8rem; font-weight: 500; }
.status-draft     { background: #e5e7eb; color: #374151; }
.status-submitted { background: #dbeafe; color: #1e40af; }
.status-approved, .status-cleared, .status-reported { background: #d1fae5; color: #065f46; }
.status-rejected  { background: #fee2e2; color: #991b1b; }
.status-warning   { background: #fef3c7; color: #92400e; }

/* ---------- Dashboard stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { padding: 18px; border-radius: 10px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.stat-label { font-size: .85rem; color: #6b7280; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 6px; color: #111827; }
.stat-blue   { border-right: 4px solid #3b82f6; }
.stat-green  { border-right: 4px solid #10b981; }
.stat-red    { border-right: 4px solid #ef4444; }
.stat-gray   { border-right: 4px solid #9ca3af; }
.stat-purple { border-right: 4px solid #8b5cf6; }
.stat-orange { border-right: 4px solid #f97316; }
.stat-indigo { border-right: 4px solid #6366f1; }
.stat-teal   { border-right: 4px solid #14b8a6; }

/* ---------- Reports cards ---------- */
.reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.report-card { display: block; padding: 22px; border-radius: 10px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.06); color: #111827; }
.report-card:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 4px 12px rgba(0,0,0,.08); transition: all .2s; }
.report-card .icon { font-size: 2.2rem; }
.report-card h3 { margin: 8px 0; }
.report-card p { color: #6b7280; margin: 0; font-size: .9rem; }

/* ---------- Invoice view ---------- */
.invoice-meta { display: grid; grid-template-columns: 1fr 1fr 200px; gap: 14px; margin-bottom: 18px; }
.meta-card { background: #fff; padding: 14px 18px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.meta-card h3 { margin: 0 0 8px 0; font-size: 1rem; color: #374151; }
.qr-img { max-width: 160px; max-height: 160px; }
code.hash { font-size: .78rem; word-break: break-all; }
.muted { color: #6b7280; }

.totals { background: #fff; padding: 12px 16px; border-radius: 8px; margin: 14px 0; text-align: left; }
.totals.end { max-width: 360px; margin-right: auto; }
.totals-row { padding: 4px 0; }
.totals-grand { font-weight: 700; font-size: 1.1rem; border-top: 1px dashed #d1d5db; padding-top: 8px; margin-top: 8px; color: #1f4ed8; }

/* ---------- Filters / search ---------- */
.filters, .search-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; background: #fff; padding: 10px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.filters input, .filters select, .search-bar input { width: auto; flex: 0 1 auto; }

/* ---------- Login ---------- */
body.blank { background: #f0f4ff; }
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; padding: 36px 32px; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.07); width: 360px; text-align: center; }
.login-card h1 { font-size: 2rem; margin: 0 0 4px 0; }
.login-card .muted { margin-bottom: 18px; }
.login-card .hint { margin-top: 14px; font-size: .82rem; }
.login-card code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }

/* ---------- Error pages ---------- */
.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 6rem; margin: 0; color: #ef4444; }

/* ---------- Misc ---------- */
.grand th, .grand td { font-weight: 700; background: #f9fafb; border-top: 2px solid #d1d5db; }
pre { background: #f9fafb; padding: 12px; border-radius: 6px; overflow-x: auto; }
details summary { cursor: pointer; padding: 6px 0; }

@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .invoice-meta { grid-template-columns: 1fr; }
}
