@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@600;700;800&display=swap');

:root {
    --primary: #ec953c;
    --primary-dark: #c9721d;
    --ink: #1c2420;
    --ink-soft: #2b3630;
    --paper: #faf9f6;
    --card-bg: #ffffff;
    --border: #e3ddd0;
    --text: #24291f;
    --text-light: #6b7268;
    --danger: #b3261e;
    --success: #2e7d32;
    --risk-high: #c62828;
    --risk-medium: #e8a317;
    --risk-tolerable: #6a9955;
    --risk-low: #2e7d32;
    --radius: 6px;
    --stripe-h: 8px;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--paper);
    color: var(--text);
    line-height: 1.5;
}
h1, h2, h3, h4 {
    font-family: "Archivo", -apple-system, "Segoe UI", sans-serif;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Hazard-stripe divider — the one deliberate signature motif, used sparingly */
.hazard-stripe {
    height: var(--stripe-h);
    background: repeating-linear-gradient(
        135deg,
        var(--primary) 0px, var(--primary) 16px,
        var(--ink) 16px, var(--ink) 32px
    );
}

.topbar { background: var(--ink); color: #fff; }
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: 14px 20px;
    display: flex; align-items: center; gap: 30px; flex-wrap: wrap;
}
.brand {
    color: #fff; font-family: "Archivo", sans-serif; font-weight: 800;
    font-size: 1.2rem; display: flex; align-items: center;
}
.brand-logo { max-height: 36px; max-width: 180px; display: block; }
.mainnav { display: flex; gap: 22px; flex: 1; align-items: center; }
.mainnav a { color: #cfd6cf; font-weight: 600; font-size: 0.92rem; padding: 4px 0; border-bottom: 2px solid transparent; }
.mainnav a:hover { color: #fff; text-decoration: none; border-bottom-color: var(--primary); }

.nav-dropdown { position: relative; }
.nav-dropdown summary {
    color: #cfd6cf; font-weight: 600; font-size: 0.92rem; cursor: pointer;
    list-style: none; padding: 4px 0; user-select: none;
}
.nav-dropdown summary::-webkit-details-marker { display: none; }
.nav-dropdown summary::after { content: ' \25BE'; font-size: 0.7rem; }
.nav-dropdown summary:hover { color: #fff; }
.nav-dropdown-menu {
    position: absolute; top: 100%; left: 0; margin-top: 8px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18); min-width: 170px; z-index: 50;
    display: flex; flex-direction: column; padding: 6px 0;
}
.nav-dropdown-menu a {
    color: var(--text) !important; font-weight: 500 !important; padding: 8px 14px !important;
    border-bottom: none !important; white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: var(--paper); text-decoration: none; }
/* Close other open dropdowns when this one opens (best-effort, no JS) */
.nav-dropdown[open] summary::after { content: ' \25B4'; }
.user-menu { display: flex; align-items: center; gap: 14px; color: #cfd6cf; font-size: 0.88rem; }
.user-menu a { color: #fff; }
.role-badge {
    background: rgba(236,149,60,0.22); color: var(--primary);
    padding: 2px 9px; border-radius: 20px;
    font-size: 0.72rem; margin-left: 6px; font-weight: 600;
}

.page-wrap { max-width: 1200px; margin: 0 auto; padding: 30px 20px 60px; }

.login-wrap {
    max-width: 380px; margin: 8vh auto 0; background: var(--card-bg);
    border-radius: var(--radius); box-shadow: 0 4px 24px rgba(28,36,32,0.12);
    overflow: hidden;
}
.login-wrap .hazard-stripe { height: 6px; }
.login-wrap-inner { padding: 32px; }
.login-wrap h1 { font-size: 1.35rem; margin: 0 0 4px; }

.card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; margin-bottom: 20px;
}
.card h2, .card h3 { margin-top: 0; }

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.95rem; border-left: 3px solid; }
.flash-success { background: #eef6ee; color: var(--success); border-color: var(--success); }
.flash-error { background: #fbeceb; color: var(--danger); border-color: var(--danger); }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    box-sizing: border-box; min-height: 40px; line-height: 1.2;
    background: var(--primary); color: #fff; border: none;
    padding: 9px 20px; border-radius: var(--radius); cursor: pointer;
    font-family: inherit; font-size: 0.9rem; font-weight: 600; text-decoration: none;
    transition: background 0.15s ease;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: #eeece5; color: var(--text); }
.btn-secondary:hover { background: #e2ded3; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f1f19; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; min-height: 32px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 0.88rem; color: var(--ink-soft); }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 220px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=file], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 0.95rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(236,149,60,0.18);
}
textarea { min-height: 80px; resize: vertical; }
.help-text { color: var(--text-light); font-size: 0.82rem; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive table { min-width: 480px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--paper); font-weight: 700; color: var(--ink-soft); font-size: 0.82rem; }
tr:hover td { background: #fbfaf7; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.74rem; font-weight: 700; }
.badge-active, .badge-approved { background: #eaf4ea; color: var(--success); }
.badge-draft, .badge-on_hold { background: #fdf1e2; color: #9a6300; }
.badge-completed { background: #eae7f7; color: #4a3c9e; }

.risk-high { background: var(--risk-high); color: #fff; }
.risk-medium { background: var(--risk-medium); color: #3a2c00; }
.risk-tolerable { background: var(--risk-tolerable); color: #fff; }
.risk-low { background: var(--risk-low); color: #fff; }
.risk-pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; }

.hazard-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; background: var(--paper); }
.hazard-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.hazard-row-head strong { font-family: "Archivo", sans-serif; color: var(--ink); }
.remove-row { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.85rem; font-weight: 600; }
.link-danger { background: none; border: none; color: var(--danger); cursor: pointer; font-size: inherit; font-family: inherit; padding: 0; text-decoration: underline; }
.link-danger:hover { color: #8f1f19; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 600; font-size: 0.9rem; }
.tabs a.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.project-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; margin-bottom: 22px; }
.actions-row { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }

.checklist-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--paper); }
.checklist-box label { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 8px; color: var(--text); }

.doc-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; background: #fff; }
.doc-group summary { padding: 10px 14px; cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--ink-soft); list-style: none; }
.doc-group summary::-webkit-details-marker { display: none; }
.doc-group summary::before { content: '\25B8'; display: inline-block; margin-right: 8px; font-size: 0.75rem; }
.doc-group[open] summary::before { content: '\25BE'; }
.doc-group .checklist-box { margin: 0 14px 14px; }

.stat-card { border-left: 3px solid var(--primary); }
.stat-card h2 { font-family: "Archivo", sans-serif; }

.site-footer { text-align: center; color: var(--text-light); font-size: 0.8rem; padding: 30px 0 10px; }

@media (max-width: 640px) {
    .topbar-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
    .mainnav { flex-direction: column; align-items: flex-start; width: 100%; gap: 12px; }
    .nav-dropdown { width: 100%; }
    .nav-dropdown-menu {
        position: static; box-shadow: none; border: none; background: transparent;
        margin-top: 8px; padding: 0 0 0 4px; min-width: 0;
    }
    .nav-dropdown-menu a { color: #cfd6cf !important; padding: 6px 0 !important; }
    .nav-dropdown-menu a:hover { background: transparent; color: #fff !important; }
    .user-menu { width: 100%; justify-content: space-between; }

    .page-wrap { padding: 20px 14px 50px; }
    .login-wrap { max-width: none; margin: 4vh 12px 0; }
    .login-wrap-inner { padding: 24px 20px; }
    .card { padding: 16px; }
    .project-header { flex-direction: column; align-items: stretch; }
    .actions-row { flex-direction: column; align-items: stretch; }
    .actions-row .btn, .actions-row form { width: 100%; text-align: center; }
    .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .tabs a { flex-shrink: 0; }
    .form-row { flex-direction: column; gap: 0; }
    .form-row .form-group { min-width: 0; width: 100%; }
    .qr-poster-inner { padding: 30px 20px; }
    .qr-poster-code { width: 220px; height: 220px; }
}


/* ---- Form action buttons ---- */
/* Long forms: title on the left, Save/Cancel on the right of the same row */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 22px; }
.page-head h1 { margin: 0; }
.action-bar { display: flex; gap: 10px; align-items: center; margin: 0; }
/* Short forms: buttons sit at the bottom of the card, set apart by a divider */
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
/* Checkbox rows (e.g. user form) */
.check-row { display: flex; align-items: flex-start; gap: 10px; font-weight: 400 !important; font-size: 0.9rem; line-height: 1.4; margin: 0 0 10px; color: var(--text) !important; cursor: pointer; }
.check-row input { margin-top: 3px; flex-shrink: 0; width: auto; }
.project-header .actions-row { margin: 0; }

@media (max-width: 720px) {
    .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
    .page-head h1 { font-size: 1.5rem; }
    .action-bar .btn, .form-actions .btn { flex: 1 1 0; white-space: nowrap; }
    .action-bar .btn:first-child, .form-actions .btn:first-child { flex: 2 1 0; }
    .page-head h1 .help-text { display: block; font-size: 0.85rem; margin-top: 4px; }
    /* Button rows on view pages: two per row instead of one tall stack */
    .actions-row { flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 8px; margin: 0; }
    .actions-row .btn { flex: 1 1 calc(50% - 4px); width: auto; }
    .actions-row form { flex: 1 1 100%; width: auto; text-align: center; }
}
