/* Leimaus-hallintakäyttöliittymän tyylit */
:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #d8dadf;
    --text: #1f2329;
    --muted: #5a6371;
    --primary: #2962ff;
    --primary-hover: #1e4cd9;
    --danger: #c0392b;
    --success: #2e7d32;
    --warning: #b87800;
    --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* --- Kirjautumisnäkymä --- */
.screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}
.card h1 {
    margin: 0 0 6px;
    font-size: 28px;
    color: var(--primary);
}
.card p { margin: 0 0 20px; }
label {
    display: block;
    margin-bottom: 14px;
    font-weight: 500;
    color: var(--text);
}
/* Tekstilabelit: input/select/textarea omalle rivilleen täydellä leveydellä */
label > input:not([type=checkbox]):not([type=radio]),
label > select,
label > textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
}
/* Checkbox- ja radio-labelit: kentät inline, sopiva väli tekstin kanssa */
label > input[type=checkbox],
label > input[type=radio] {
    margin-right: 8px;
    vertical-align: middle;
}
input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], select, textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    font-family: inherit;
}
/* Lomakkeessa olevat labelit modaaleissa eivät tarvitse lihavointia tekstille
   jos niitä käytetään checkbox-rivinä — pidetään harmaampi, kevyt label. */
.modal label {
    font-weight: 500;
}
/* Toolbarin sisällä label voi olla yhdellä rivillä: "Asiakas: <select>" */
.toolbar label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}
.toolbar label > input:not([type=checkbox]):not([type=radio]),
.toolbar label > select,
.toolbar label > textarea {
    display: inline-block;
    width: auto;
    margin-top: 0;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    border-color: transparent;
}
button {
    cursor: pointer;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
}
button:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
button.secondary:hover { background: var(--bg); }
button.danger { background: var(--danger); }
button.link {
    background: none;
    color: var(--primary);
    padding: 0;
    text-decoration: underline;
}
button.link:hover { background: none; color: var(--primary-hover); }
.error {
    color: var(--danger);
    margin-top: 12px;
    min-height: 18px;
}

/* --- Pääsovellus: sidebar + main --- */
#app {
    display: flex;
    height: 100vh;
}
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.brand {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    padding: 20px 20px 16px;
}
.sidebar-tenant-wrapper {
    padding: 0 12px 8px;
    border-bottom: 1px solid var(--border);
}
.sidebar-company-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    padding: 6px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-tenant-select {
    width: 100%;
    font-size: 0.875rem;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}
.sidebar nav {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
}
.nav-section {
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
}
.nav-label {
    padding: 10px 20px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted, #888);
    pointer-events: none;
    user-select: none;
}
.sidebar nav a {
    padding: 8px 20px 8px 28px;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
    font-size: 0.925rem;
}
.sidebar nav a.nav-company {
    padding: 10px 20px;
    font-weight: 500;
    font-size: 1rem;
}
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active {
    background: var(--bg);
    border-left-color: var(--primary);
    font-weight: 500;
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
main {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

/* --- Otsikot ja toiminnot --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h2 {
    margin: 0;
    font-size: 22px;
}
.toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

/* --- Taulukot --- */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    /* HUOM: ei overflow: hidden, koska se leikkaa absoluuttisesti
       sijoitetut pudotusvalikot taulukon rivien yli. Pyöristys
       saavutetaan border-radius:llä joka näkyy itse table-tagilla. */
}
th, td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.04em;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button {
    padding: 5px 10px;
    font-size: 12px;
    margin-left: 6px;
}
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.green  { background: #e3f3e6; color: var(--success); }
.badge.red    { background: #fbe6e3; color: var(--danger); }
.badge.yellow { background: #fff4d6; color: #8a6500; }
.badge.gray   { background: var(--bg); color: var(--muted); }

/* --- Taulukon riviaktion-solu --- */
td.row-actions {
    white-space: nowrap;
    text-align: right;
}
td.row-actions button {
    padding: 4px 10px;
    font-size: 12px;
    margin-left: 4px;
}

/* --- Tyhjä tila --- */
.empty {
    text-align: center;
    padding: 40px;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 8px;
}

/* --- Modaali (dialog) --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 100;
}
.modal {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; }
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* --- Toast --- */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}
.toast {
    background: var(--text);
    color: white;
    padding: 12px 18px;
    border-radius: 6px;
    box-shadow: var(--shadow);
    max-width: 360px;
    animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- Pieni näyttö --- */
@media (max-width: 720px) {
    #app { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; }
    .brand { padding: 12px 16px; }
    .sidebar nav { flex-direction: row; padding: 0; overflow-x: auto; }
    .sidebar nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
    .sidebar nav a.active { border-left: none; border-bottom-color: var(--primary); }
    .sidebar-footer { padding: 8px 12px; flex-direction: row; }
    main { padding: 16px; }
}

/* --- Tunniste-koodit isolla fontilla (laitekoodit, UID:t) --- */
code, .mono {
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 13px;
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 3px;
}

/* Laitesarake leimaushistoriassa — koodi yläriville, näyttönimi alle */
td code + .muted { display: block; margin-top: 2px; }

/* --- Raporttisivun pikavalinnat (kuluvan/edellisen jakson napit) --- */
.report-presets {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0 24px;
}
.preset-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.preset-label {
    font-size: 13px;
    color: var(--muted);
    min-width: 160px;
}
.preset-group button.preset {
    padding: 6px 14px;
    font-size: 13px;
}

/* --- Leimausten aikaväli-modaali --- */
.stamps-range-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0;
}
.stamps-range-options > button {
    padding: 14px 16px;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.stamps-range-options > button:hover {
    background: var(--bg);
    border-color: var(--primary);
}
.stamps-range-options > button strong {
    display: block;
    margin-bottom: 4px;
}

