:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #e2e4e9;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #3454d1;
    --color-primary-dark: #2540a8;

    --status-idea: #9ca3af;
    --status-idea_review: #f59e0b;
    --status-design: #3b82f6;
    --status-client_review: #f97316;
    --status-approved: #10b981;
    --status-published: #059669;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* El atributo hidden siempre gana, así ningún display puesto a mano
   (inline o por clase) puede dejar algo visible por error. */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar__brand a { font-weight: 700; font-size: 1.1rem; color: var(--color-text); }
.topbar__nav { display: flex; gap: 20px; }
.topbar__nav a { color: var(--color-text-muted); font-weight: 500; }
.topbar__user { display: flex; align-items: center; gap: 14px; }
.topbar__username { color: var(--color-text-muted); font-size: .9rem; }

.link-button {
    background: none; border: none; color: var(--color-text-muted);
    cursor: pointer; font-size: .9rem; padding: 0;
}
.link-button:hover { color: var(--color-primary); }

.notif-bell { position: relative; font-size: 1.1rem; }
.notif-count {
    position: absolute; top: -6px; right: -10px;
    background: #e11d48; color: #fff; border-radius: 999px;
    font-size: .65rem; padding: 1px 5px; font-weight: 700;
}

/* Auth */
.auth-box {
    max-width: 360px;
    margin: 10vh auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 32px;
}
.auth-subtitle { color: var(--color-text-muted); margin-top: -8px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--color-text-muted); }

input, textarea, select {
    font: inherit;
    padding: 9px 11px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: #fff;
    color: var(--color-text);
}

textarea {
    width: 100%;
    resize: vertical;
    display: block;
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
}
button:hover { background: var(--color-primary-dark); }
button.secondary { background: var(--color-border); color: var(--color-text); }
button.secondary:hover { background: #d3d6dd; }
button.danger { background: #dc2626; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: .9rem; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }

/* Calendar */
.calendar-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.calendar-toolbar h2 { margin: 0; text-transform: capitalize; }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}
.calendar-grid__weekday {
    text-align: center; font-size: .75rem; color: var(--color-text-muted);
    text-transform: uppercase; font-weight: 700; padding-bottom: 4px;
}
.calendar-day {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    min-height: 110px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.calendar-day--outside { opacity: .4; }
.calendar-day__number { font-size: .8rem; color: var(--color-text-muted); font-weight: 700; }

.pub-chip {
    display: block;
    font-size: .72rem;
    padding: 4px 6px;
    border-radius: 6px;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pub-chip--idea { background: var(--status-idea); }
.pub-chip--idea_review { background: var(--status-idea_review); }
.pub-chip--design { background: var(--status-design); }
.pub-chip--client_review { background: var(--status-client_review); }
.pub-chip--approved { background: var(--status-approved); }
.pub-chip--published { background: var(--status-published); }

.status-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 700;
    color: #fff;
    padding: 3px 10px;
    border-radius: 999px;
}
.status-badge--idea { background: var(--status-idea); }
.status-badge--idea_review { background: var(--status-idea_review); }
.status-badge--design { background: var(--status-design); }
.status-badge--client_review { background: var(--status-client_review); }
.status-badge--approved { background: var(--status-approved); }
.status-badge--published { background: var(--status-published); }

/* Timeline de estados */
.status-timeline {
    display: flex; align-items: flex-start;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 12px; padding: 20px 16px; margin-bottom: 20px;
    overflow-x: auto;
}
.status-timeline__step {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    min-width: 84px; flex-shrink: 0;
}
.status-timeline__dot {
    width: 30px; height: 30px; border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700;
    background: var(--color-border); color: var(--color-text-muted);
}
.status-timeline__label {
    font-size: .72rem; text-align: center; color: var(--color-text-muted);
    line-height: 1.2; max-width: 90px;
}
.status-timeline__step--done .status-timeline__dot {
    background: var(--color-primary); color: #fff;
}
.status-timeline__step--done .status-timeline__label { color: var(--color-text); }
.status-timeline__step--current .status-timeline__dot {
    background: #fff; color: var(--color-primary); border: 3px solid var(--color-primary);
    box-shadow: 0 0 0 3px rgba(52,84,209,.15);
}
.status-timeline__step--current .status-timeline__label { color: var(--color-text); font-weight: 700; }
.status-timeline__connector {
    flex: 1; height: 2px; background: var(--color-border);
    margin-top: 15px; min-width: 16px;
}
.status-timeline__connector--done { background: var(--color-primary); }

@media (max-width: 720px) {
    .status-timeline__step { min-width: 64px; }
    .status-timeline__label { max-width: 64px; font-size: .65rem; }
}

/* Publication detail */
.pub-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 12px; padding: 20px; margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.pub-section {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 12px; padding: 20px; margin-bottom: 20px;
}
.pub-section h3 { margin-top: 0; }

.piece-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.piece-card {
    border: 1px solid var(--color-border); border-radius: 10px; overflow: hidden;
    background: #fafafa; cursor: pointer;
}
.piece-card img, .piece-card video { width: 100%; height: 160px; object-fit: cover; display: block; }
.piece-card img.img-broken { object-fit: contain; background: #e5e7eb; cursor: default; }

/* Pieza vigente (la más nueva) grande y destacada; versiones anteriores chicas */
.piece-current-wrap { position: relative; max-width: 480px; margin-bottom: 18px; }
.piece-card--current {
    border: 2px solid var(--color-primary);
    box-shadow: 0 4px 14px rgba(52,84,209,.15);
}
.piece-card--current img, .piece-card--current video { height: 360px; }
.piece-current-badge {
    position: absolute; top: 10px; left: 10px; z-index: 2;
    background: var(--color-primary); color: #fff; font-size: .72rem; font-weight: 700;
    padding: 3px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em;
}
.piece-history-label {
    font-size: .8rem; color: var(--color-text-muted); font-weight: 600;
    margin: 4px 0 8px;
}
.piece-grid--history { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.piece-card--old {
    opacity: .65; transition: opacity .15s;
}
.piece-card--old:hover { opacity: 1; }
.piece-card--old img, .piece-card--old video { height: 80px; }

.reference-list { display: flex; flex-direction: column; gap: 14px; }
.reference-item { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.reference-item__media { width: 200px; flex-shrink: 0; cursor: default; }
.reference-item__notes { flex: 1; min-width: 200px; }

.link-preview-card { display: block; color: var(--color-text); text-decoration: none; }
.link-preview-card:hover { text-decoration: none; }
.link-preview-card__img { width: 100%; height: 120px; object-fit: cover; display: block; }
.link-preview-card__body {
    display: block; padding: 10px 12px; font-size: .85rem; line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
    -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
@media (max-width: 560px) {
    .reference-item__media { width: 100%; }
}

.piece-actions {
    display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--color-border);
    background: #fafafa; cursor: default;
}
.piece-action-btn {
    flex: 1; text-align: center; font-size: .78rem; font-weight: 600;
    padding: 6px 8px; border-radius: 6px; border: 1px solid var(--color-border);
    background: #fff; color: var(--color-text); cursor: pointer; text-decoration: none;
    white-space: nowrap;
}
.piece-action-btn:hover { background: var(--color-bg); text-decoration: none; }

.history-item {
    border-left: 2px solid var(--color-border);
    padding: 4px 0 4px 14px;
    margin-left: 4px;
    font-size: .85rem;
}
.history-item time { color: var(--color-text-muted); font-size: .75rem; display: block; }

.comment {
    border: 1px solid var(--color-border); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px;
}
.comment__meta { font-size: .75rem; color: var(--color-text-muted); margin-bottom: 4px; }
.comment img { max-width: 100%; border-radius: 8px; margin-top: 6px; }

/* Annotation canvas modal */
.annotator-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,.75);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.annotator-modal[hidden] { display: none; }
.annotator-box {
    background: #fff; border-radius: 12px; padding: 16px; max-width: 95vw; max-height: 95vh;
    display: flex; flex-direction: column; gap: 10px;
}
.annotator-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.annotator-tools input[type=color] { width: 34px; height: 34px; padding: 0; border: none; }
.annotator-toolgroup { display: flex; gap: 4px; }
.annotator-toolgroup button.active-tool { background: var(--color-primary); color: #fff; }
.annotator-canvas-wrap { position: relative; overflow: auto; max-width: 90vw; max-height: 70vh; }
.annotator-canvas-wrap canvas { position: absolute; top: 0; left: 0; touch-action: none; }
.annotator-text-input {
    position: absolute;
    z-index: 10;
    background: transparent;
    border: 1px dashed rgba(0,0,0,.4);
    padding: 0 2px;
    font-weight: 700;
    min-width: 40px;
    transform: translate(-2px, -2px);
}

/* Mis pendientes */
.pending-row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 8px; border-bottom: 1px solid var(--color-border);
    color: var(--color-text); text-decoration: none;
}
.pending-row:last-child { border-bottom: none; }
.pending-row:hover { background: var(--color-bg); text-decoration: none; }
.pending-row__title { flex: 1; }
.pending-row__assignee { color: var(--color-text-muted); font-size: .85rem; }
.pending-row__date { color: var(--color-text-muted); font-size: .85rem; white-space: nowrap; }

.pending-section--info { background: var(--color-bg); }
.pending-section--info .pending-row { opacity: .8; }

.quota-row { margin-bottom: 16px; }
.quota-row:last-child { margin-bottom: 0; }
.quota-row__head {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: .9rem; margin-bottom: 6px;
}
.quota-row__head span { color: var(--color-text-muted); font-size: .82rem; }
.quota-row__bar {
    height: 8px; border-radius: 999px; background: var(--color-border); overflow: hidden;
}
.quota-row__fill { height: 100%; background: var(--color-primary); border-radius: 999px; }

@media (max-width: 720px) {
    .calendar-grid { grid-template-columns: repeat(7, minmax(38px, 1fr)); }
    .calendar-day { min-height: 70px; padding: 3px; }
    .pub-chip { font-size: .6rem; padding: 2px 3px; }
}
