:root {
    --ink: #1c2b23;
    --paper: #f7f3e8;
    --line: #c9a86a;
    --accent: #8b3a2b;
    --accent2: #1f5c4a;
    --muted: #6b6355;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #e9e4d8;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 20px;
}

/* ---------- LOGIN SCREEN ---------- */
#appScreen {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: center;
}

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 70vh;
}

.login-box {
    background: #fffdf8;
    border: 1px solid #ddd3bd;
    border-radius: 10px;
    padding: 32px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .08);
    display: flex;
    flex-direction: column;
}

.login-box h1 {
    font-size: 1.2rem;
    margin: 0 0 6px;
    text-align: center;
}

.login-box .sub {
    font-size: .82rem;
    color: var(--muted);
    text-align: center;
    margin-bottom: 20px;
}

.login-box input {
    margin-bottom: 14px;
}

.login-box button {
    padding: 12px;
    background: var(--accent2);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.login-box button:hover {
    background: #164a3c;
}

.login-box button:disabled {
    opacity: .6;
    cursor: default;
}

.login-box .error {
    color: var(--accent);
    font-size: .82rem;
    margin-bottom: 12px;
    display: none;
}

h1 {
    font-size: 1.4rem;
    letter-spacing: .04em;
    margin: 5px;
}

.sub {
    color: var(--muted);
    font-size: .88rem;
    margin-bottom: 6px;
    text-align: center;
    max-width: 520px;
}

.steps {
    display: flex;
    gap: 18px;
    margin-bottom: 22px;
    font-size: .78rem;
    color: var(--muted);
    flex-wrap: wrap;
    justify-content: center;
}

.steps span b {
    color: var(--accent2);
}

/* ---------- FORM ---------- */
.panel {
    background: #fffdf8;
    border: 1px solid #ddd3bd;
    border-radius: 10px;
    padding: 22px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .06);
}

.field {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.row .field {
    flex: 1;
    min-width: 130px;
}

label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 700;
}

input {
    border: 1px solid #d6cbb0;
    border-radius: 7px;
    padding: 11px 12px;
    font-size: 1rem;
    font-family: inherit;
    background: #fffef9;
    color: var(--ink);
    width: 100%;
}

input:focus {
    outline: none;
    border-color: var(--accent2);
    box-shadow: 0 0 0 3px rgba(31, 92, 74, .14);
}

.from-to-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.from-to-row .field {
    flex: 1;
}

.swap-btn {
    margin-bottom: 15px !important;
    background: #f0ead9;
    border: 1px solid #d6cbb0;
    border-radius: 7px;
    width: 45px;
    height: 45px;
    min-width: 42px;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--accent2);
    margin-bottom: 1px;
}

.swap-btn:hover {
    background: #e7dfc7;
}

.swap-btn:active {
    transform: scale(.94);
}

.actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.actions > button {
    min-width: 120px;
}

button.primary {
    flex: 1;
    background: var(--accent2);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 13px 16px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .02em;
    cursor: pointer;
}

button.primary:hover {
    background: #164a3c;
}

button.ghost {
    background: none;
    border: 1px solid #d6cbb0;
    border-radius: 7px;
    padding: 13px 16px;
    cursor: pointer;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 600;
}

button.ghost:hover {
    background: #f0ead9;
}

.hint {
    font-size: .72rem;
    color: var(--muted);
    margin-top: -8px;
    margin-bottom: 14px;
}

.editing-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #fdf3e2;
    border: 1px solid #ecd9ac;
    border-radius: 7px;
    padding: 10px 14px;
    font-size: .82rem;
    color: var(--accent);
    margin-bottom: 14px;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent2);
    font-weight: 700;
    font-size: .82rem;
    cursor: pointer;
    text-decoration: underline;
}

button.ghost.small.danger {
    color: var(--accent);
    border-color: #e5c9bd;
}

button.ghost.small.danger:hover {
    background: #fbeee9;
}

/* ---------- PREVIEW MODAL ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 43, 35, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-box {
    background: #fffdf8;
    border-radius: 10px;
    padding: 20px;
    width: 100%;
    max-width: 640px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, .25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    font-weight: 700;
}

.modal-frame {
    width: 100%;
    aspect-ratio: 194/90;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
    border-radius: 6px;
    overflow: hidden;
}

.modal-actions {
    margin-top: 16px;
}

.modal-actions button {
    width: 100%;
}

.topbar {
    width: 100%;
    max-width: 520px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar h1 {
    margin: 5px 0;
}

button.ghost.small {
    padding: 8px 14px;
    font-size: .82rem;
    white-space: nowrap;
}

.save-status {
    text-align: center;
    font-size: .8rem;
    color: var(--accent2);
    min-height: 1.2em;
    margin-top: 8px;
}

.save-status.is-error {
    color: var(--accent);
}

/* ---------- SAVED TICKETS ---------- */
#savedPanel {
    margin-top: 24px;
}

.saved-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.saved-header h2 {
    font-size: 1.05rem;
    margin: 0;
    letter-spacing: .02em;
}

.saved-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.saved-empty {
    color: var(--muted);
    font-size: .85rem;
    text-align: center;
    padding: 18px 0;
}

.saved-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #ece4cf;
    border-radius: 8px;
    padding: 10px 14px;
    background: #fffef9;
    flex-wrap: wrap;
}

.saved-info {
    min-width: 0;
}

.saved-route {
    font-weight: 700;
    font-size: .92rem;
}

.saved-meta {
    font-size: .75rem;
    color: var(--muted);
    margin-top: 2px;
}

.saved-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}


#previewSection {
    margin-top: 28px;
    width: 100%;
    max-width: 640px;
    display: none;
}

#previewSection.show {
    display: block;
}

.preview-label {
    font-size: .78rem;
    color: var(--muted);
    margin-bottom: 8px;
    text-align: center;
}

.preview-frame {
    width: 100%;
    aspect-ratio: 194/90;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .16);
    border-radius: 6px;
    overflow: hidden;
}

.print-note {
    text-align: center;
    font-size: .76rem;
    color: var(--muted);
    margin-top: 12px;
}

.footer-credit {
    margin-top: 16px;
    text-align: center;
    font-size: .82rem;
    color: var(--muted);
    padding-bottom: 4px;
}

.footer-credit a {
    color: var(--accent2);
    text-decoration: none;
    font-weight: 700;
}

.footer-credit a:hover {
    text-decoration: underline;
}

/* ---------- TICKET MARKUP (shared) ---------- */
.ticket {
    width: 100%;
    height: 100%;
    background: var(--paper);
    border: 2px solid var(--ink);
    position: relative;
    padding: 5mm 6mm;
    display: flex;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    box-sizing: border-box;
}

.ticket-main {
    width: 76%;
    padding-right: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 2px dashed var(--line);
}

.ticket-stub {
    width: 24%;
    padding-left: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.poribahan-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: .02em;
    text-transform: uppercase;
    line-height: 1.15;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1.5px solid var(--ink);
    padding-bottom: 4px;
    margin-bottom: 6px;
}

.serial-tag {
    font-size: .65rem;
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
}

.route {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0;
}

.route .place {
    font-size: 1rem;
    font-weight: 700;
    max-width: 42%;
    word-break: break-word;
    line-height: 1.15;
}

.route .arrow {
    font-size: 1.1rem;
    color: var(--accent2);
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 10px;
    font-size: .72rem;
}

.meta-grid .k {
    color: var(--muted);
    text-transform: uppercase;
    font-size: .6rem;
    letter-spacing: .05em;
}

.meta-grid .v {
    font-weight: 700;
}

.ticket-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-top: 1px dashed var(--line);
    padding-top: 4px;
    margin-top: 4px;
}

.fare-box .k {
    font-size: .6rem;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: .05em;
}

.fare-box .v {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent2);
}

.footer-note {
    font-size: .6rem;
    color: var(--muted);
    text-align: right;
    line-height: 1.3;
}

.stub-label {
    font-size: .58rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    text-align: center;
}

.stub-name {
    font-size: .72rem;
    font-weight: 800;
    color: var(--accent);
    text-align: center;
    line-height: 1.2;
}

.stub-route {
    font-size: .66rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.25;
}

.stub-fare {
    font-size: .9rem;
    font-weight: 800;
    color: var(--accent2);
    text-align: center;
}

/* ---------- PRINT ---------- */
#printArea {
    display: none;
}

@media print {
    @page {
        size: 194mm 90mm;
        margin: 0;
    }

    html,
    body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff;
    }

    body * {
        visibility: hidden;
    }

    #printArea,
    #printArea * {
        visibility: visible;
    }

    #printArea {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 194mm;
        margin: 0;
        padding: 0;
    }

    .print-ticket-slot {
        width: 194mm;
        height: 90mm;
        margin: 2px;
    }
}