:root {
    --bg: #eef1f0;
    --surface: #ffffff;
    --surface-muted: #f5f7f6;
    --ink: #17201d;
    --muted: #66736e;
    --line: #d8dfdc;
    --brand: #15804a;
    --brand-dark: #0d5f36;
    --danger: #c53a3a;
    --warning: #a96700;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Arial, sans-serif; }
button, input, textarea, select { font: inherit; }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #17201d;
}

.login-layout {
    width: min(760px, 100%);
    display: grid;
    grid-template-columns: 0.85fr 1.15fr;
    overflow: hidden;
    border: 1px solid #34413c;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
}

.login-brand-panel {
    min-height: 430px;
    display: flex;
    align-items: flex-end;
    gap: 14px;
    padding: 34px;
    background: var(--brand);
    color: #fff;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    border-radius: 8px;
    background: #fff;
    color: var(--brand-dark);
    font-size: 24px;
    font-weight: 900;
}

.login-brand-panel div:last-child { display: grid; gap: 2px; }
.login-brand-panel strong { font-size: 24px; }
.login-brand-panel span { color: rgba(255, 255, 255, 0.78); font-size: 13px; }

.login-form { display: grid; align-content: center; gap: 20px; padding: 46px; }
.login-form header span, .topbar span, .operator span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.login-form h1 { margin: 5px 0 0; font-size: 28px; }
.login-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 800; }
.login-form input { min-height: 44px; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; color: var(--ink); }
.login-form input:focus { border-color: var(--brand); outline: 2px solid rgba(21, 128, 74, 0.15); }
.login-form button, .sidebar form button { min-height: 44px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 800; }
.login-form button:hover, .sidebar form button:hover { background: var(--brand-dark); }
.alert { padding: 11px 12px; border: 1px solid #efb0b0; border-radius: 6px; background: #fff1f1; color: #9f2525; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 18px; background: #17201d; color: #fff; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; padding: 0 8px 24px; border-bottom: 1px solid #34413c; }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 19px; }
.brand small { color: #9caaa5; }
.sidebar nav { display: grid; gap: 6px; margin-top: 24px; }
.sidebar nav a { padding: 11px 12px; border-radius: 6px; color: #b9c5c1; text-decoration: none; font-weight: 700; }
.sidebar nav a:hover, .sidebar nav a.active { background: #26332e; color: #fff; }
.sidebar form { margin-top: auto; }
.sidebar form button { width: 100%; background: #26332e; }

.main-content { min-width: 0; padding: 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.topbar h1 { margin: 4px 0 0; font-size: 27px; }
.operator { display: grid; gap: 3px; text-align: right; }
.operator strong { font-size: 14px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.metrics article { min-width: 0; display: grid; gap: 7px; padding: 16px; border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: 7px; background: var(--surface); }
.metrics span, .metrics small { color: var(--muted); font-size: 12px; }
.metrics strong { font-size: 22px; overflow-wrap: anywhere; }
.metric-link { width: max-content; min-height: 30px; display: inline-grid; place-items: center; padding: 0 10px; border-radius: 6px; background: #26332e; color: #fff; font-size: 12px; font-weight: 800; text-decoration: none; }
.metric-link:hover { background: var(--brand-dark); }
.metrics .metric-warning { border-left-color: var(--warning); }
.metrics .metric-yellow { border-left-color: #d7a600; background: #fffdf1; }
.metrics .metric-purple { border-left-color: #7857b8; background: #faf7ff; }
.metrics-dense { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.data-section { margin-bottom: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.data-section > header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.data-section h2 { margin: 0; font-size: 18px; }
.data-section header span { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th { padding: 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; text-align: left; text-transform: uppercase; }
td { padding: 12px 10px; border-bottom: 1px solid #e8ecea; font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td small { color: var(--muted); }
.empty { padding: 30px; color: var(--muted); text-align: center; }
.status { display: inline-flex; padding: 5px 8px; border-radius: 999px; background: #e7ecea; color: #4f5d58; font-size: 11px; font-weight: 800; }
.status-active, .status-completed { background: #e1f4e9; color: var(--brand-dark); }
.status-passive { background: #f1f4f2; color: #66736e; }
.status-pending { background: #fff1d8; color: #885400; }
.status-failed, .status-blocked, .status-cancelled { background: #fde7e7; color: #a52626; }
.amount-incoming { color: var(--brand-dark); font-weight: 800; }
.amount-outgoing { color: var(--danger); font-weight: 800; }

.section-link { color: var(--brand-dark); font-size: 13px; font-weight: 800; text-decoration: none; }
.page-alert { margin-bottom: 16px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.page-alert-success { border-color: #9dd6b5; background: #e9f8ef; color: var(--brand-dark); }
.page-alert-error { border-color: #efb0b0; background: #fff1f1; color: #9f2525; }

.workflow-forms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.workflow-forms form, .workflow-card { display: flex; min-width: 0; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.workflow-forms header span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.workflow-forms h2 { margin: 3px 0 0; font-size: 17px; }
.workflow-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.workflow-forms label, .account-filters label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 800; }
.workflow-forms input, .workflow-forms select, .account-filters input, .account-filters select, .account-actions input, .account-actions select { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); padding: 0 10px; }
.workflow-forms button, .workflow-card button, .account-filters button, .account-actions button, .credential-button { min-height: 38px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 800; padding: 0 12px; }
.workflow-forms form > button, .workflow-card > button { margin-top: auto; }
.workflow-forms button:disabled { cursor: not-allowed; opacity: 0.5; }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(23, 32, 29, 0.54); }
.modal-backdrop[hidden] { display: none; }
.modal-panel { width: min(720px, 100%); max-height: min(760px, calc(100vh - 48px)); overflow: auto; border-radius: 8px; background: var(--surface); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32); }
.modal-form { display: grid; gap: 16px; padding: 20px; }
.modal-form header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.modal-form header span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.modal-form h2 { margin: 3px 0 0; font-size: 20px; }
.modal-close { width: 34px; min-height: 34px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-weight: 900; }
.modal-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
.modal-form textarea, .modal-form select, .modal-form input { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); padding: 10px 12px; }
.modal-form textarea { min-height: 230px; resize: vertical; line-height: 1.45; }
.modal-form select, .modal-form input { min-height: 42px; }
.modal-form > button { min-height: 42px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 900; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions button { min-height: 42px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 900; padding: 0 12px; }
.button-danger { border: 0; border-radius: 6px; background: var(--danger) !important; color: #fff; cursor: pointer; font-weight: 900; }
.button-danger:hover { background: #9f2525 !important; }
.modal-error { margin: 0; padding: 10px 12px; border: 1px solid #efb0b0; border-radius: 6px; background: #fff1f1; color: #9f2525; font-size: 13px; font-weight: 800; }
.match-summary { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-muted); }
.match-summary div { display: grid; gap: 3px; }
.match-summary span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.match-summary strong { overflow-wrap: anywhere; font-size: 15px; }

.account-filters { display: grid; grid-template-columns: 180px minmax(240px, 1fr) auto auto; align-items: end; gap: 10px; margin-bottom: 18px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.account-filters a { min-height: 38px; display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 800; }
.account-list table { min-width: 1060px; }
.account-row td { transition: background 0.15s ease; }
.account-yellow td { background: #fff8cf; border-bottom-color: #e8d77d; }
.account-purple td { background: #f1eaff; border-bottom-color: #c5b0e9; }
.account-green td { background: #e6f7ec; border-bottom-color: #aad7ba; }
.stock-row td { transition: background 0.15s ease; }
.stock-available td { background: #e6f7ec; border-bottom-color: #aad7ba; }
.stock-paired td { background: #f1eaff; border-bottom-color: #c5b0e9; }
.stock-cancelled td { background: #fff1f1; border-bottom-color: #efb0b0; }
.workflow-status { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.workflow-yellow { background: #ead15a; color: #594600; }
.workflow-purple { background: #7857b8; color: #fff; }
.workflow-green { background: var(--brand); color: #fff; }
.account-actions { min-width: 220px; }
.account-actions form { display: flex; gap: 7px; }
.account-actions span { color: var(--muted); font-size: 12px; }
.credential-button { min-width: 130px; background: #26332e; }
.credential-button:disabled { opacity: 0.65; }
.provider-forms { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.provider-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.provider-list table { min-width: 820px; }
.inline-edit { display: grid; grid-template-columns: minmax(130px, 1fr) 100px auto; gap: 7px; align-items: center; margin: 0; }
.pp-inline-edit { grid-template-columns: minmax(140px, 1fr) repeat(2, 90px) auto; }
.inline-edit input { width: 100%; min-height: 34px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); padding: 0 9px; }
.inline-edit button { min-height: 34px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 800; padding: 0 10px; }

.provider-page .main-content { padding: 18px; }
.provider-page .topbar { margin-bottom: 14px; }
.provider-page .metrics { gap: 8px; margin-bottom: 12px; }
.provider-page .metrics article { gap: 4px; padding: 10px 12px; }
.provider-page .metrics strong { font-size: 18px; }
.provider-page .workflow-forms { gap: 8px; margin-bottom: 12px; }
.provider-page .workflow-forms form { gap: 8px; padding: 10px; }
.provider-page .workflow-forms h2 { font-size: 15px; }
.provider-page .workflow-forms input,
.provider-page .workflow-forms select { min-height: 32px; padding: 0 8px; }
.provider-page .workflow-forms button { min-height: 32px; }
.provider-page .data-section { margin-bottom: 12px; padding: 10px; }
.provider-page .data-section > header { margin-bottom: 8px; }
.provider-page .data-section h2 { font-size: 16px; }
.provider-page th { padding: 6px 7px; font-size: 10px; }
.provider-page td { padding: 7px; font-size: 12px; }
.provider-page .provider-grid { gap: 12px; }
.provider-page .provider-list table { min-width: 0; }
.provider-page .inline-edit { grid-template-columns: minmax(95px, 1fr) 70px auto; gap: 4px; }
.provider-page .pp-inline-edit { grid-template-columns: minmax(95px, 1fr) repeat(2, 58px) auto; }
.provider-page .inline-edit input,
.provider-page .inline-edit button { min-height: 30px; padding: 0 7px; font-size: 12px; }

@media (max-width: 950px) {
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workflow-forms { grid-template-columns: 1fr 1fr; }
    .provider-forms { grid-template-columns: 1fr; }
    .provider-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .login-layout { grid-template-columns: 1fr; }
    .login-brand-panel { min-height: 120px; align-items: center; padding: 24px; }
    .login-form { padding: 30px 24px; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; width: 100%; height: auto; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 14px; }
    .brand { border: 0; padding: 0; }
    .sidebar nav { grid-column: 1 / -1; display: flex; overflow-x: auto; margin: 0; }
    .sidebar form { margin: 0; }
    .sidebar form button { padding: 0 14px; }
    .main-content { padding: 18px 14px; }
    .metrics { grid-template-columns: 1fr 1fr; }
    .workflow-forms { grid-template-columns: 1fr; }
    .provider-forms { grid-template-columns: 1fr; }
    .account-filters { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
    .metrics { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; }
}
