/*
 * Midgard biz - shared styles on top of w2ui.
 * Colours are tokens; the dark set applies when <html data-theme="dark">.
 */
:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --border: #d9dde3;
    --text: #1f2328;
    --text-muted: #646b75;
    --accent: #2f6fdb;
    --accent-text: #ffffff;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --shadow: 0 8px 28px rgba(15, 23, 42, 0.10);
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
    --bg: #15171a;
    --surface: #1e2125;
    --surface-2: #24282d;
    --border: #363b42;
    --text: #e6e8eb;
    --text-muted: #9aa1ab;
    --accent: #5b93f0;
    --accent-text: #0d1117;
    --danger: #ff8a80;
    --danger-bg: #3a1f1f;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
}

/* ---------------------------------------------------------------------------
   Login
--------------------------------------------------------------------------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 16px;
    box-sizing: border-box;
}

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

.login-card h1 {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 600;
}

.login-card .subtitle {
    margin: 0 0 22px;
    color: var(--text-muted);
}

.login-card label {
    display: block;
    margin: 0 0 5px;
    color: var(--text-muted);
    font-weight: 500;
}

.login-card .w2ui-input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 14px;
    padding: 8px 10px;
    font-size: 14px;
}

.login-card .remember {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0 18px;
    color: var(--text);
    font-weight: normal;
}

.login-card .w2ui-btn {
    width: 100%;
    margin: 0;
    padding: 9px;
    font-size: 14px;
}

.login-error {
    display: none;
    margin-bottom: 14px;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--danger-bg);
    color: var(--danger);
}

.login-error.visible {
    display: block;
}

.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
}

.theme-toggle:hover {
    color: var(--text);
}

/* ---------------------------------------------------------------------------
   Application shell
--------------------------------------------------------------------------- */
#layout {
    position: fixed;
    inset: 0;
}

.brand {
    padding: 0 10px 0 4px;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
}

.brand small {
    margin-left: 6px;
    color: var(--text-muted);
    font-weight: normal;
}

.page {
    padding: 24px 28px;
    max-width: 960px;
}

.page h2 {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 600;
}

.page .muted {
    color: var(--text-muted);
}

.page .placeholder {
    margin-top: 18px;
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   Dark theme fixes for w2ui parts the generated theme cannot reach
--------------------------------------------------------------------------- */
html[data-theme="dark"] .w2ui-input,
html[data-theme="dark"] input.w2ui-input,
html[data-theme="dark"] select.w2ui-input,
html[data-theme="dark"] textarea.w2ui-input {
    background-color: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

html[data-theme="dark"] .w2ui-btn-blue {
    color: #fff;
}

/* ---------------------------------------------------------------------------
   Pages with tabs (full height)
--------------------------------------------------------------------------- */
.page-host {
    height: 100%;
}

.page.page-full {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: none;
    padding: 16px 20px 16px;
    box-sizing: border-box;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.page-head p {
    margin: 0;
}

.page-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.page-actions .w2ui-btn {
    margin: 0;
    min-width: 80px;
}

.tab-body {
    position: relative;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border);
    border-top: 0;
}

.tab-pane {
    position: absolute;
    inset: 0;
    overflow: auto;
}

.tab-pane[hidden] {
    display: none;
}

.fill,
.popup-form {
    height: 100%;
}

.hint {
    margin-left: 6px;
    color: var(--text-muted);
    font-size: 11px;
}

.error-list {
    margin: 0;
    padding-left: 18px;
    text-align: left;
    line-height: 1.6;
}

/* ---------------------------------------------------------------------------
   List pages and popups
--------------------------------------------------------------------------- */
.grid-host {
    flex: 1;
    min-height: 0;
}

.popup-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.popup-wrap .popup-form {
    flex: 1;
    min-height: 0;
}

.popup-errors {
    margin: 10px 12px 0;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--danger-bg);
    color: var(--danger);
}

.popup-errors[hidden] {
    display: none;
}

/* ---------------------------------------------------------------------------
   Court register lookup, secrets
--------------------------------------------------------------------------- */
.w2ui-btn.inline-btn {
    margin: 0 0 0 6px;
    padding: 4px 10px;
    min-width: 0;
}

.registry-popup {
    padding: 12px 16px;
}

.registry-warning {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--danger-bg);
    color: var(--danger);
}

.registry-table {
    width: 100%;
    border-collapse: collapse;
}

.registry-table th,
.registry-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

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

.registry-table td.old {
    color: var(--text-muted);
}

.registry-table td.new {
    font-weight: 600;
}

.registry-table tr.same td {
    opacity: 0.55;
}

.secret-set {
    color: #2e7d32;
    font-weight: 600;
}

html[data-theme="dark"] .secret-set {
    color: #81c784;
}

.test-result {
    margin-left: 8px;
}

.test-result.ok {
    color: #2e7d32;
}

.test-result.fail {
    color: var(--danger);
}

/* ---------------------------------------------------------------------------
   Documents (purchase orders, ...)
--------------------------------------------------------------------------- */
.status {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
}

.status-draft {
    background: #fff3cd;
    color: #7a5b00;
}

.status-issued {
    background: #d7f0dd;
    color: #1e6b33;
}

.status-cancelled {
    background: #eceff1;
    color: #6b7178;
    text-decoration: line-through;
}

html[data-theme="dark"] .status-draft {
    background: #4a3d12;
    color: #ffe08a;
}

html[data-theme="dark"] .status-issued {
    background: #1d3d27;
    color: #8fdba4;
}

html[data-theme="dark"] .status-cancelled {
    background: #2c3036;
    color: #9aa1ab;
}

.po-totals {
    margin: 4px 0 0;
}

.page-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.popup-note {
    margin: 10px 12px 0;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-muted);
}
