/* SICAP Scanner — stil minimal, mobile-first, accesibil pe iPhone Safari */
:root {
    --bg: #f6f7f9;
    --fg: #1c2128;
    --muted: #6b7280;
    --card: #ffffff;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --ok: #16a34a;
    --star: #eab308;
    --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }

/* Topbar */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar .user { color: var(--muted); font-size: 13px; }

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    padding: 16px 20px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.stat-card.highlight { border-color: var(--star); }
.stat-num { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-lbl { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-sub { font-size: 13px; margin-top: 2px; }

/* Filters */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 12px 20px;
    background: var(--card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.filters label {
    display: flex; flex-direction: column;
    font-size: 12px; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.filters label.check {
    flex-direction: row; align-items: center; gap: 6px;
    text-transform: none; font-size: 14px; color: var(--fg);
}
.filters input[type=search],
.filters input[type=number],
.filters select {
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg);
    text-transform: none;
    color: var(--fg);
}
.filters .actions {
    display: flex; gap: 8px; align-items: flex-end;
    grid-column: 1 / -1;
}
.filters button, .btn-link, .btn-reset {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--card);
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    color: var(--fg);
    display: inline-block;
}
.filters button { background: var(--fg); color: white; border: none; }
.btn-link { display: inline-block; }
.btn-reset {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--danger);
    font-weight: 600;
}
.btn-reset:hover { background: #fee2e2; text-decoration: none; }

/* Scan bar */
.scan-bar {
    padding: 14px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; gap: 14px; align-items: center;
}
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.results-meta {
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.results-meta .per-page { font-size: 13px; }
.results-meta .per-page a {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 4px;
    border-radius: 4px;
    color: var(--muted);
    text-decoration: none;
}
.results-meta .per-page a.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}
.results-meta .per-page a:hover:not(.active) {
    background: var(--bg);
    color: var(--fg);
}

/* Header-e sortabile */
.sort-link {
    color: var(--muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.sort-link:hover { color: var(--fg); text-decoration: none; }
.sort-link.sort-active { color: var(--primary); font-weight: 700; }
.sort-arrow { font-size: 10px; }

/* Paginare */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 18px 20px;
    flex-wrap: wrap;
    background: var(--card);
    border-top: 1px solid var(--border);
}
.pg-btn, .pg-num {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--fg);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
}
.pg-btn:hover:not(.disabled), .pg-num:hover:not(.active) {
    background: var(--bg);
    border-color: var(--primary);
    text-decoration: none;
}
.pg-num.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 700;
    cursor: default;
}
.pg-btn.disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}
.pg-ellipsis {
    padding: 0 6px;
    color: var(--muted);
}
.pg-info {
    margin-left: 12px;
    font-size: 13px;
}
@media (max-width: 600px) {
    .pg-info { display: none; }
    .pg-btn, .pg-num { min-width: 30px; height: 30px; font-size: 13px; }
}

/* Tabel */
.contracts {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}
.contracts th, .contracts td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.contracts thead th {
    background: var(--bg);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    position: sticky; top: 0; z-index: 1;
}
.contracts tr.seen { opacity: 0.55; }
.contracts tr.star { background: #fffbeb; }
.contracts tr.star.seen { background: #fef9c3; }

.title-link {
    font-weight: 500;
    color: var(--fg);
    text-decoration: none;
    display: block;
    cursor: pointer;
}
.title-link:hover { color: var(--primary); text-decoration: underline; }
.title div:first-child { font-weight: 500; }
.tag {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg);
    border-radius: 4px;
    font-size: 11px;
    color: var(--muted);
    margin-right: 4px;
}

.cat-dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    vertical-align: middle;
}

.actions-cell { white-space: nowrap; }
.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 16px;
    margin-right: 4px;
}
.btn-icon:hover { background: var(--bg); }
.btn-icon.btn-ext, .btn-icon.btn-details {
    text-decoration: none;
    color: var(--primary);
    font-weight: 700;
}
.btn-icon.btn-ext:hover, .btn-icon.btn-details:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.contracts tr.star .mark-int { color: var(--star); border-color: var(--star); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.footer { padding: 16px 20px; }

/* Login */
.page-login {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f1f5f9, #e0e7ff);
}
.login-card {
    background: var(--card);
    padding: 32px 28px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; }
.login-card label {
    display: flex; flex-direction: column;
    margin-bottom: 14px;
    font-size: 13px; color: var(--muted);
}
.login-card input {
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
}
.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.err {
    background: #fee2e2;
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 14px;
}

/* Responsive: ascunde coloane mai puțin importante pe mobil */
@media (max-width: 720px) {
    .contracts th:nth-child(6),
    .contracts td:nth-child(6),
    .contracts th:nth-child(7),
    .contracts td:nth-child(7),
    .contracts th:nth-child(8),
    .contracts td:nth-child(8) { display: none; }
    .stat-num { font-size: 22px; }
    .topbar { padding: 10px 14px; }
    .stats, .filters, .scan-bar { padding-left: 12px; padding-right: 12px; }
    .contracts th, .contracts td { padding: 8px 10px; font-size: 13px; }
}

/* ─── Modal detalii contract ─────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.open { display: flex; }
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.18s ease;
}
.modal-card {
    position: relative;
    background: var(--card);
    border-radius: 14px;
    width: 100%;
    max-width: 720px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: slideUp 0.22s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-head {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-cat-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}
.modal-head h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.35;
    flex: 1;
    color: var(--fg);
}
.modal-close {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted);
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
}
.modal-close:hover { background: var(--bg); color: var(--fg); }

.modal-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--bg);
    border-radius: 0 0 14px 14px;
}
.modal-sicap-link {
    background: var(--primary);
    color: white;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}
.modal-sicap-link:hover { background: var(--primary-dark); text-decoration: none; }
.modal-close-btn {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 9px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.modal-close-btn:hover { background: var(--bg); }

/* Conținut modal */
.md-row.md-hero {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.md-badge {
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.md-source, .md-state {
    background: var(--bg);
    color: var(--muted);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
}
.md-state { color: var(--ok); font-weight: 600; }

.md-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 22px 0 8px;
    font-weight: 700;
}
.md-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}
.md-mt { margin-top: 10px; }
.md-cell {
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 6px;
}
.md-lbl {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 3px;
}
.md-val {
    font-size: 14px;
    color: var(--fg);
    word-break: break-word;
}
.md-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.md-money { font-weight: 700; color: var(--primary-dark); font-size: 16px; }
.md-cpv {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
}
.md-supplier {
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 6px;
    font-weight: 500;
}
.md-match { display: flex; gap: 8px; align-items: center; }
.md-mt-term { font-size: 13px; color: var(--muted); }
.md-fetched {
    margin-top: 14px;
    font-size: 11px;
    color: var(--muted);
    text-align: right;
}

@media (max-width: 600px) {
    .modal { padding: 10px; }
    .modal-card { max-height: calc(100vh - 20px); }
    .modal-head { padding: 14px 16px; }
    .modal-body { padding: 16px; }
    .modal-foot { padding: 12px 16px; flex-direction: column-reverse; }
    .modal-foot .modal-sicap-link, .modal-foot .modal-close-btn { width: 100%; text-align: center; }
    .md-grid { grid-template-columns: 1fr; }
}

/* ─── Autorități țintă ─────────────────────────── */
.aut-table tr.eval-due  { background: #fef2f2; }
.aut-table tr.eval-done { background: #f0fdf4; }
.aut-table tr.pri-1     { border-left: 3px solid var(--danger); }
.aut-table tr.pri-3     { opacity: 0.75; }

.pri-cell { width: 90px; }
.pri-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}
.pri-badge-1 { background: #fee2e2; color: #b91c1c; }
.pri-badge-2 { background: #fef3c7; color: #92400e; }
.pri-badge-3 { background: #e5e7eb; color: #4b5563; }

.eval-cell { width: 40px; font-size: 18px; text-align: center; }

.status-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.status-lead      { background: #e0e7ff; color: #3730a3; }
.status-contacted { background: #fef3c7; color: #92400e; }
.status-quoted    { background: #ddd6fe; color: #5b21b6; }
.status-won       { background: #d1fae5; color: #047857; }
.status-lost      { background: #fee2e2; color: #b91c1c; }

.btn-icon.btn-check:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-icon.btn-edit:hover  { background: var(--star);    color: white; border-color: var(--star); }
.btn-icon.btn-del:hover   { background: var(--danger);  color: white; border-color: var(--danger); }
.btn-icon.btn-enrich {
    background: #ddd6fe;
    color: #5b21b6;
    border-color: #c4b5fd;
}
.btn-icon.btn-enrich:hover { background: #5b21b6; color: white; border-color: #5b21b6; }
.btn-icon.btn-suggest {
    background: #fef9c3;
    color: #92400e;
    border-color: #fde68a;
}
.btn-icon.btn-suggest:hover { background: #eab308; color: white; border-color: #eab308; }
.btn-icon[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn-icon.needs-cif {
    background: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
    position: relative;
}
.btn-icon.needs-cif::after {
    content: '!';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    background: #dc2626;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.btn-icon.needs-cif:hover { background: var(--star); color: white; border-color: var(--star); }

/* Formular în modal */
.aut-form .md-grid label,
.aut-form .full {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}
.aut-form .full { margin-top: 12px; }
.aut-form input, .aut-form select, .aut-form textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--fg);
    background: var(--card);
    font-family: inherit;
}
.aut-form .req { color: var(--danger); }
.err-msg { color: var(--danger); font-size: 13px; flex: 1; }

/* Pagina import */
.import-page { max-width: 800px; margin: 24px auto; padding: 0 20px; }
.import-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 22px 24px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.import-card h2 { margin-top: 0; font-size: 18px; }
.import-card p { color: var(--muted); font-size: 14px; }
.import-card details { margin: 10px 0 18px; }
.import-card details summary { cursor: pointer; color: var(--primary); font-size: 14px; }
.import-card pre {
    background: var(--bg);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 12px;
    margin-top: 8px;
}
.import-card input[type=file] {
    display: block;
    margin: 12px 0;
    padding: 8px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    width: 100%;
    background: var(--bg);
}
.import-card code {
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 12px;
}
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 20px auto;
    max-width: 800px;
    font-size: 14px;
}
.alert-ok  { background: #d1fae5; color: #047857; border: 1px solid #6ee7b7; }
.alert-err { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
