:root {
    --navy: #172431;
    --navy-2: #20313f;
    --ink: #1f2b35;
    --muted: #7d8992;
    --line: #dfe5e9;
    --line-soft: #e9edf0;
    --paper: #fff;
    --page: #f5f7f8;
    --weekend: #fafbfc;
    --blue: #2469c5;
    --blue-soft: #eef5ff;
    --yellow: #fff0a8;
    --yellow-border: #e0bd38;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--page);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
    height: 66px;
    padding: 0 30px;
    background: var(--navy);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center;
    background: #fff; color: var(--navy);
    font-size: 11px; font-weight: 850;
}
.brand-name { font-size: 16px; font-weight: 750; letter-spacing: -.25px; }
.top-actions { display: flex; align-items: center; gap: 7px; }

.week-navigation {
    height: 34px;
    display: flex;
    align-items: center;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 7px;
    overflow: hidden;
    background: rgba(255,255,255,.055);
}
.week-navigation a {
    height: 32px; min-width: 31px; padding: 0 9px;
    display: grid; place-items: center;
    color: rgba(255,255,255,.88);
    text-decoration: none;
    font-size: 18px;
    border-right: 1px solid rgba(255,255,255,.12);
}
.week-navigation a:last-child { border-right: 0; }
.week-navigation a:hover { background: rgba(255,255,255,.1); }
.week-navigation .today-link { min-width: 88px; font-size: 11px; font-weight: 650; }

.share-button, .editor-button, .save-button {
    height: 34px; padding: 0 13px;
    border-radius: 7px; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    cursor: pointer;
}
.share-button { background: #fff; color: var(--navy); border: 1px solid #fff; }
.editor-button { background: #fff; color: var(--navy); border: 1px solid #fff; }
.save-button { display: none; background: var(--blue); color: #fff; border: 1px solid var(--blue); min-width: 72px; }
.save-button:disabled { opacity: .55; cursor: default; }

.main { width: min(1530px, calc(100% - 44px)); margin: 0 auto; padding: 28px 0 35px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 17px; }
.eyebrow { color: #8a959d; font-size: 10px; font-weight: 800; letter-spacing: .13em; margin-bottom: 7px; }
h1 { margin: 0; color: #1d2d3b; font-size: 31px; line-height: 1.05; letter-spacing: -1.1px; }
.mode-pill {
    padding: 6px 10px; border-radius: 20px;
    background: #edf1f3; color: #64717a;
    font-size: 10px; font-weight: 750;
}
.editor-mode .mode-pill { background: var(--blue-soft); color: var(--blue); }

.rota-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(28,43,54,.045);
}
.rota-table-wrap { min-width: 0; overflow-x: auto; }
table { width: 100%; min-width: 990px; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
th:last-child, td:last-child { border-right: 0; }
thead th {
    height: 58px; padding: 8px 7px;
    background: #f8fafb; color: #64727d;
    text-align: center; font-size: 11px; font-weight: 800;
}
thead th:first-child { text-align: left; padding-left: 17px; }
thead th span { display: block; }
thead th small { display: block; margin-top: 3px; color: #9aa5ad; font-size: 9px; font-weight: 550; }
.technician-column { width: 215px; }
.weekend { background: #f5f7f8; }

tbody td { height: 64px; padding: 7px; }
.technician { background: #fff; padding: 7px 14px !important; }
.technician { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 31px; height: 31px; flex: 0 0 31px;
    display: grid; place-items: center;
    border-radius: 9px; background: #edf1f4; color: #536675;
    font-size: 10px; font-weight: 850;
}
.tech-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; font-weight: 720; }
.weekend-cell { background: var(--weekend); }

.cell-content { min-width: 0; }
.viewer-shift {
    height: 38px;
    display: flex; align-items: center; justify-content: center;
    color: #33424e; font-size: 12px; font-weight: 700;
    border-radius: 7px;
}
.viewer-shift.custom-value { color: #c62828; }
.shift-select {
    display: none;
    width: 100%; height: 38px;
    padding: 0 8px; border: 1px solid #ccd5db; border-radius: 7px;
    background: #fff; color: #344450;
    text-align: center; text-align-last: center;
    font-size: 11px; font-weight: 650; outline: none;
}
.shift-select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(36,105,197,.1); }
.editor-mode .shift-select { display: block; }
.editor-mode .viewer-shift { display: none; }
.shift-select.changed { background: var(--blue-soft); border-color: #a8c7ea; }

.custom-shift, .user-note {
    display: none; width: 100%; margin-top: 4px;
    height: 22px; padding: 2px 6px;
    border: 1px solid #d2d9de; border-radius: 5px;
    background: #fff; color: #4d5b65; font-size: 9px; outline: none;
}
.editor-mode .user-note { display: block; }
.editor-mode .custom-shift { display: none; }
.editor-mode .custom-cell .custom-shift { display: block; }
.custom-shift { color: #c62828; font-weight: 700; }
.custom-shift:focus { border-color: #d14a4a; box-shadow: 0 0 0 2px rgba(198,40,40,.10); }
.user-note:focus { border-color: var(--blue); }

.late-cell { background: var(--yellow) !important; }
.late-cell .viewer-shift, .late-cell .shift-select { background: var(--yellow); }
.late-cell .viewer-shift { border: 1px solid rgba(224,189,56,.35); }
.custom-cell .viewer-shift { background: #fff4f4; color: #c62828; }
.custom-cell .shift-select { color: #c62828; border-color: #e4aaaa; background: #fff7f7; }

.common-note {
    background: #fbfcfd;
    border-left: 1px solid var(--line);
    padding: 16px 13px;
    min-width: 0;
}
.common-note-title { font-size: 10px; font-weight: 800; color: #56646f; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px; }
.common-note-content { color: #485761; font-size: 10px; line-height: 1.5; white-space: normal; }
.muted-note { color: #a0a9b0; }
.common-note textarea {
    display: none; width: 100%; min-height: 115px; resize: vertical;
    padding: 7px; border: 1px solid #ccd5db; border-radius: 6px;
    background: #fff; color: #485761; font-size: 10px; outline: none;
}
.editor-mode .common-note-content { display: none; }
.editor-mode .common-note textarea { display: block; }

.rota-footer {
    min-height: 40px; display: flex; align-items: center; justify-content: space-between;
    padding: 8px 4px; color: #8a959d; font-size: 9px;
}
.legend { display: flex; align-items: center; gap: 5px; }
.legend-late { width: 8px; height: 8px; border-radius: 2px; background: var(--yellow); border: 1px solid var(--yellow-border); }
.footer-status { font-weight: 600; }

/* Share */
.share-panel { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(16,27,36,.48); backdrop-filter: blur(3px); }
.share-panel.open { display: flex; }
.share-dialog { width: min(780px, 100%); max-height: 90vh; overflow: hidden; background: #fff; border-radius: 12px; box-shadow: 0 24px 70px rgba(12,22,30,.25); display: flex; flex-direction: column; }
.share-head { padding: 17px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; }
.share-head strong { display: block; font-size: 14px; }
.share-head span { display: block; margin-top: 3px; color: #89949c; font-size: 10px; }
#closeShare { border: 0; background: transparent; color: #77838c; font-size: 24px; line-height: 1; cursor: pointer; }
.share-preview { padding: 10px 12px 12px; background: #f3f5f6; min-height: 0; overflow: auto; flex: 1 1 auto; }
.preview-image { width: 100%; height: auto; display: block; border: 1px solid var(--line); }
.preview-loading { min-height: 150px; padding: 65px 15px; text-align: center; color: #8c979f; font-size: 11px; }
.share-actions { padding: 11px 14px 6px; display: flex; justify-content: flex-end; gap: 7px; flex: 0 0 auto; }
.secondary-action, .primary-action { height: 35px; padding: 0 13px; border-radius: 7px; font-size: 10px; font-weight: 750; cursor: pointer; }
.secondary-action { background: #fff; color: #3d4c57; border: 1px solid #ccd5db; }
.primary-action { background: var(--blue); color: #fff; border: 1px solid var(--blue); }
.share-status { padding: 0 15px 9px; color: #8a959d; font-size: 9px; flex: 0 0 auto; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 70; padding: 10px 13px; border: 1px solid #dbe5eb; border-radius: 7px; background: #fff; color: #40515d; box-shadow: 0 10px 30px rgba(15,30,40,.13); font-size: 10px; font-weight: 700; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
    .rota-area { grid-template-columns: 1fr; }
    .common-note { border-left: 0; border-top: 1px solid var(--line); min-height: 90px; }
    .common-note textarea { max-width: 360px; }
}
@media (max-width: 700px) {
    .topbar { height: 58px; padding: 0 12px; }
    .brand-name { font-size: 13px; }
    .week-navigation .today-link { display: none; }
    .top-actions { gap: 4px; }
    .share-button, .editor-button, .save-button { padding: 0 8px; font-size: 9px; }
    .main { width: calc(100% - 18px); padding-top: 20px; }
    .page-heading { align-items: flex-start; }
    h1 { font-size: 24px; }
    .mode-pill { margin-top: 5px; }
}


/* ============================================================
   Editor PIN
   ============================================================ */

.pin-panel {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(16, 27, 36, .48);
    backdrop-filter: blur(3px);
}

.pin-panel.open {
    display: flex;
}

.pin-dialog {
    width: min(360px, 100%);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(12, 22, 30, .25);
    overflow: hidden;
}

.pin-head {
    padding: 17px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.pin-head strong {
    display: block;
    font-size: 14px;
}

.pin-head span {
    display: block;
    margin-top: 3px;
    color: #89949c;
    font-size: 10px;
}

#closePin {
    border: 0;
    background: transparent;
    color: #77838c;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

#pinForm {
    padding: 18px;
}

#pinInput {
    width: 100%;
    height: 42px;
    padding: 0 11px;
    border: 1px solid #ccd5db;
    border-radius: 7px;
    background: #fff;
    color: #344450;
    font-size: 14px;
    text-align: center;
    letter-spacing: .15em;
    outline: none;
}

#pinInput:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(36, 105, 197, .1);
}

.pin-submit {
    width: 100%;
    height: 38px;
    margin-top: 12px;
    border: 1px solid var(--blue);
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
}

.pin-submit:disabled {
    opacity: .55;
    cursor: default;
}

.pin-error {
    min-height: 17px;
    margin-top: 7px;
    color: #c62828;
    font-size: 10px;
    text-align: center;
}


/* ============================================================
   Full Page PIN
   ============================================================ */

.pin-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--page);
}

.pin-dialog {
    width: min(360px, 100%);
    padding: 30px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(20, 35, 45, .10);
    text-align: center;
}

.pin-brand {
    width: 42px;
    height: 42px;
    margin: 0 auto 15px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--navy);
    color: #fff;
    font-size: 12px;
    font-weight: 850;
}

.pin-dialog h1 {
    font-size: 22px;
    letter-spacing: -.5px;
}

.pin-dialog p {
    margin: 8px 0 20px;
    color: var(--muted);
    font-size: 11px;
}

#viewerPinInput {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid #ccd5db;
    border-radius: 7px;
    outline: none;
    text-align: center;
    letter-spacing: .2em;
    font-size: 15px;
}

#viewerPinInput:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(36,105,197,.1);
}

#viewerPinButton {
    width: 100%;
    height: 40px;
    margin-top: 12px;
    border: 1px solid var(--blue);
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
}

#viewerPinButton:disabled {
    opacity: .55;
    cursor: default;
}